Collections-类集工具类
定义了若干用于类集和映射的算法,这些算法被定义为静态方法
package com.Set; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class ConnectionsDemo { public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); for (String string : list) { System.out.print(string + " "); } // 交换顺序 Collections.swap(list, 1, 2); for (String string : list) { System.out.print(string + " "); } // 自然排序 Collections.sort(list); for (String string : list) { System.out.print(string + " "); } // 二分法查找 System.out.println(Collections.binarySearch(list, "B")); //打乱顺序 Collections.shuffle(list); //填充方法 Collections.fill(list, "E"); } }