在android中排序字符串arraylist

编程入门 行业动态 更新时间:2024-10-22 10:46:07
本文介绍了在android中排序字符串arraylist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个名为 names 的字符串数组列表.如何按字母顺序对数组列表进行排序?

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/javase/6/docs/api/java/util/Collections.html#sort%28java.util.List%29

根据其元素的自然顺序,将指定列表按升序排序.列表中的所有元素都必须实现 Comparable 接口.此外,列表中的所有元素必须相互比较(即,e1pareTo(e2) 不得为列表中的任何元素 e1 和 e2 抛出 ClassCastException).

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, e1pareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the list).

String 实现 Comparable:

java.lang 类字符串

java.lang Class String

java.lang.Object 扩展为java.lang.String

java.lang.Object extended by java.lang.String

所有实现的接口:可序列化、CharSequence、可比较

All Implemented Interfaces: Serializable, CharSequence, Comparable

http://download.oracle/javase/6/docs/api/java/lang/String.html

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

更多推荐

[db:关键词]

本文发布于:2023-04-16 10:37:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/884957.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   android   arraylist

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!