在Android的排序字符串数组列表 [英] sorting string arraylist in android

查看:157
本文介绍了在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 implements 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

这篇关于在Android的排序字符串数组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆