문제
제네릭 클래스 ArrayList 및 Collections를 바탕으로 점수 및 단어를 정렬하는 문제입니다 실행순서를 클릭하세요
86 89 90
apple banana carrot
프로그램 코드
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 }
}