제네릭 클래스 ArrayList 및 Collections를 바탕으로 점수 및 단어를 정렬하는 문제입니다 이를 해결하는 다음 프로그램을 해석하세요
86 89 90 apple banana carrot
프로그램 시작
먼저, 점수 정렬 후 출력
단어 정렬 후 출력
프로그램 종료
// 파일명 : ./Chapter19/GenericTest.java
import java.util.*;
public class GenericTest {
// 프로그램 시작
1 public static void main( String[] args ) {
// 먼저, 점수 정렬 후 출력
ArrayList<Integer> scores = new ArrayList<>();
scores.add( 90 );
scores.add( 89 );
scores.add( 86 );
2 Collections.sort( scores );
for( int i = 0; i < scores.size(); i++ )
System.out.print( scores.get(i) + " " );
3 System.out.println();
// 단어 정렬 후 출력
ArrayList<String> words = new ArrayList<>();
words.add( "carrot" );
words.add( "banana" );
words.add( "apple" );
4 Collections.sort( words );
for( int i = 0; i < words.size(); i++ )
System.out.print( words.get(i) + " " );
// 프로그램 종료
5 }
}
※ 실행순서 및 메모리상태는 A키(이전) 및 D키(다음)를 눌러도 확인할 수 있습니다