总结一下java.util.Collections类内部的静态方法。
checkedCollection(Collection
checkedList(List
checkedMap(Map
checkedSet
checkedSortedMap(SortedMap
checkedSortedSet(SortedSet
以上方法产生Collection或者Collection的具体子类型的动态类型安全的师徒。在不可能实用静态检查版本时使用这些方法。
max(Collection)
min(Collection)
返回参数Collection中最大或最小元素-采用Collection中的内置自然比较法。
max(Collection,Comparator)
min(Collection , Comparator)
返回参数Collection中最大或最小元素-采用Collection中的Comparator进行比较。
indexOfSubList(List source,List target)
返回target在source中第一次出现的位置,或者在找不到时返回-1
lastIndexOfSubList(List source,List target)
返回target在source中最后一次出现的位置,或者在找不到时返回-1
replaceAll(List
使用newVal替换所有的oldVal
reverse(List)
逆序所有元素次序
reverseOrder()
reverseOrder(Comparator
返回一个Comparator,它可以逆转实现了Comparator
rotate(List,int distance)
所有元素向后移动distance个位置,将末尾的元素循环到前面来。
shuffle(List)
shuffle(List,Random)
随机改变指定列表的顺序。
sort(List
sort(List
排序List
copy(List super T> dest, List src)
将src中的元素复制到dest
swap(List,int i , int j )
交换list中位置i和位置j的元素,通常比自己写的代码快
fill(List super T > , T x )
用对象x替换list中的所有元素
nCopies( int n , T x )
返回大小为n的List
disjoint( Collection,Collection )
当两个集合没有任何相同元素时,返回true
frequency( Collection,Object x )
返回Collection中等于x的元素个数
emptyList()
emptyMap()
emptySet()
返回不可变的空List,Map或Set。这些方法都是泛型的。因此所产生的结果将被参数化为所希望的类型
singleton(T x )
singletonList(T x )
singletonMap(K key, V value)
产生不可变的Set
list(Enumeration
产生一个ArrayList
enumeration(Collection
为参数生成一个旧式的Enumeration
手机扫一扫
移动阅读更方便
你可能感兴趣的文章