Collections工具类介绍
Collection工具类是一个提供了操作Set、List和Map等集合发工具类,Collection中提供了一系列惊天的方法对集合元素进行排序、查询、和修改等操作。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| import java.util.*;
public class Test { public static void main(String[] args) { List list=new ArrayList(); list.add("asc"); list.add("ascgj"); list.add("sbs"); list.add("adbnde"); list.add("dnjj"); System.out.println(list); Collections.reverse(list); System.out.println(list);
Collections.shuffle(list); System.out.println(list); Collections.sort(list); System.out.println(list); Collections.swap(list,1,2); System.out.println(list); } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| import java.util.*;
public class Test { public static void main(String[] args) { List list=new ArrayList(); list.add("asc"); list.add("ascgj"); list.add("sbs"); list.add("adbnde"); list.add("dnjj"); System.out.println(list); System.out.println(Collections.max(list)); System.out.println(Collections.frequency(list,"asc")); ArrayList arrayList=new ArrayList(); for (int i=0;i<list.size();i++){ arrayList.add(""); }
Collections.copy(arrayList,list); System.out.println(arrayList);
Collections.replaceAll(list,"asc","唐末"); System.out.println(list); } }
|