Collections工具类
1.作用:用来操作Collection和Map的工具类
2.常用方法:
reverse(List):反转List中元素的顺序
shuffle(List):对List集合元素进行随机
sort(List):根据元素的自然顺序对指定List集合元素按升序排序
sort(List,Comparator):根据指定的Comparator产生的顺序对list集合元素进行排序
swap(List,int ,int):将指定list集合中的i处元素和j处元素进行交换
Object max(Collection):根据元素的自然顺序,返回给定集合中的最大元素
Object max(Collection,Comparator):根据Comparator指定的顺序,返回给定集合中的最大元素
Object min(Collection):根据元素的自然顺序,返回给定集合中的最小元素
Object min(Collection,Comparator):根据Comparator指定的顺序,返回给定集合中的最小元素
int frequency(Collection,Object):返回集合中指定元素出现的次数
void copy(List dest,List src):将src中的内容复制到dest中
如果需要求线程安全,可将ArrayList和HashMap转变为线程安全的,
使用synchronizedList(List list) 和 synchronizedMap(Map map)