List的排序是通过Collections.sort(List)来排序的。
|
集合 |
排序 |
遍历 |
添加 |
删除 |
|
List: ArrayList,LinkList |
Collections.sort(List) |
get(i) |
add() |
remove() |
|
Set: HashSet,TreeSet |
TreeSet:要实现Comparable接口并实现他的compareTo方法。add的时候会自动排列。 |
Iterator<E> ws = workers.iterator(); ws.hasNext(); ws.next(); |
add() |
remove() |
|
Map: HashMap,TreeMap |
TreeMap已经实现SortedSet接口 |
Set s = map.keySet(); Iterator遍历 |
remove() clear() |
数组的工具类:Arrays
集合的工具类:Collections
本文介绍了Java中集合的基本操作,包括List、Set、Map等类型的使用方法,并详细解释了如何进行排序、遍历、添加和删除元素。对于需要实现排序功能的TreeSet,文章特别强调了实现Comparable接口的重要性。
1871

被折叠的 条评论
为什么被折叠?



