package collections;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class collections {
public void sort1()
{
List<String> mylist=new ArrayList<String>();
mylist.add("Kobe");
mylist.add("James");
mylist.add("Druant");
collections.sort(mylist);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
import java.util.ArrayList; import java.util.Collections; import java.util.List; public class CollectionsTest { public void testSort2() { List<String> stringList = new ArrayList<String>(); stringList.add("microsoft"); stringList.add("google"); stringList.add("lenovo"); System.out.println("------------排序前-------------"); for (String string : stringList) { System.out.println("元素:" + string); } Collections.sort(stringList); //依次比较字符串首字母进行排序,先排数字,后排大小写字母 System.out.println("--------------排序后---------------"); for (String string : stringList) { System.out.println("元素:" + string); } } public static void main(String[] args) { CollectionsTest ct = new CollectionsTest(); ct.testSort2(); //调用String泛型的List } }