我有一个名为names的字符串数组列表。如何按字母顺序对数组列表进行排序?
最佳答案
ArrayList<String> names = new ArrayList<String>();
names =fillNames() // whatever method you need to fill here;
Collections.sort(names);
http://download.oracle.com/javase/6/docs/api/java/util/Collections.html#sort%28java.util.List%29
Sorts the specified list into ascending order, according to the natural ordering of its elements. All elements in the list must implement the Comparable interface. Furthermore, all elements in the list must be mutually comparable (that is, e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the list).
String
实现 Comparable
:
java.lang Class String
java.lang.Object extended by java.lang.String
All Implemented Interfaces: Serializable, CharSequence, Comparable
http://download.oracle.com/javase/6/docs/api/java/lang/String.html
关于java - 在android中对字符串数组列表进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5814791/