学生の成績を昇順に並べます.

2824 ワード

           
a)          ArrayList  
b)    Collections.sort(List list, Comparator super T> c)               
i.         
ii.   Lambda   
 */
public class Test11_Test {
    public static void main(String[] args) {
        //     ArrayList   , Student     .
        ArrayList list = new ArrayList<>();
        //             -       .
        list.add(new Student("   ",85));
        list.add(new Student("   ",63));
        list.add(new Student("   ",77));
        list.add(new Student("   ",33));
        list.add(new Student("   ",92));

        //  Collections.sort(List list, Comparator super T> c)  
        //              
        //         .
        Collections.sort(list, new Comparator() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getGrade()-o2.getGrade();
            }
        });
        System.out.println(list);

        //   lambda    ,     .
        Collections.sort(list,((o1, o2) -> o1.getGrade() - o2.getGrade()));
        //      ,          .  -     for
        for (Student student : list) {
            System.out.println(student);
        }



    }
}