在Android的排序字符串数组列表 [英] sorting string arraylist in android
问题描述
我有一个名为的名称的字符串数组列表。我如何按字母进行排序ArrayList的?
的ArrayList<串GT;名称=新的ArrayList<串GT;();
名称= fillNames()//任何你需要填写在这里;
Collections.sort(地名);
<一个href=\"http://download.oracle.com/javase/6/docs/api/java/util/Collections.html#sort%28java.util.List%29\" rel=\"nofollow\">http://download.oracle.com/javase/6/docs/api/java/util/Collections.html#sort%28java.util.List%29
对指定列表按升序进行,根据元素的自然顺序。列表中的所有元素都必须实现Comparable接口。此外,在列表中的所有元素都必须是可相互比较的(也就是说,e1.compareTo(e2)不得抛出ClassCastException E1的任何元素和E2列表)。
块引用>
字符串
工具可比
:
java.lang中的类字符串
java.lang.Object继承者
java.lang.String中
所有已实现的接口:
序列化,CharSequence中,可比
块引用>http://download.oracle.com/ JavaSE的/ 6 /文档/ API / JAVA / LANG / String.html
I have a string arraylist called names. How do I sort the arraylist in alphabetical order?
解决方案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
implementsComparable
: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
这篇关于在Android的排序字符串数组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!