package cn.edu.bjut.chapter6; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; public class ListSortTester { public static void main(String[] args) { String[] strArray = new String[] { "dtk", "abc", "ekd", "def" }; List strList = Arrays.asList(strArray); System.out.println(strList); Collections.sort(strList); System.out.println(strList); Collections.reverse(strList); System.out.println(strList); List stuList = new ArrayList(); stuList.add(new Person("李文慧", 'F')); stuList.add(new Person("白富美", 'F')); stuList.add(new Person("谢祖隆恩", 'M')); stuList.add(new Person("梁化祥", 'M')); System.out.println(stuList); Collections.sort(stuList); System.out.println(stuList); Collections.sort(stuList); System.out.println(stuList); int idx = Collections.binarySearch(stuList, new Person("白晨", 'F')); if (idx >= 0) { System.out.println("Found"); } else { System.out.println("Not Found"); } } }