import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Test { public static void main(String[] args) { List<String> list = new ArrayList<String>(); list.add("c"); list.add("b"); list.add("d"); list.add("a"); System.out.println(list);//[c, b, d, a] Collections.sort(list);//对list集合进行排序 System.out.println(list);//[a, b, c, d] } }
import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Test2 { public static void main(String[] args) { List<String> list = new ArrayList<String>(); list.add("caa"); list.add("cab"); list.add("daa"); list.add("add"); System.out.println(list);//[caa, cab, daa, add] Collections.sort(list);//对list集合进行排序 System.out.println(list);//[add, caa, cab, daa] } }