集合操作工具类Colletions
作者:互联网
1 import java.util.ArrayList; 2 import java.util.Collections; 3 import java.util.List; 4 5 public class ColletionsDemo1 { 6 public static void main(String[] args) { 7 8 // 1. 批量加数据 9 List<String> names = new ArrayList<>(); 10 //names.add("wl"); 11 //names.add("phx"); 12 Collections.addAll(names, "wl", "phx", "xw", "xp"); 13 System.out.println(names); 14 15 // 2. 打乱List集合顺序 16 Collections.shuffle(names); 17 System.out.println(names); 18 19 // 3. 将集合中元素按照默认规则排序(只能排值特性的元素) 20 List<Integer> list = new ArrayList<>(); 21 Collections.addAll(list, 33, 21 ,5, 1, 4, 6, 22, 2); 22 System.out.println(list); 23 Collections.sort(list); 24 System.out.println(list); 25 } 26 }
标签:List,list,System,Colletions,Collections,names,集合,工具,out 来源: https://www.cnblogs.com/xiao-wang-tong-xue/p/16532524.html