package quit; import javafx.print.Collation; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; public class CollectionsQuick { public static void main(String[] args) { ArrayList arr1 =new ArrayList(); arr1.add(1); arr1.add(2); arr1.add(3); arr1.add(75); arr1.add(100); arr1.add(80); System.out.println(arr1); Comparable max = Collections.max(arr1);//最大值 System.out.println("最大值"+max); Comparable min =Collections.min(arr1); System.out.println("最小值"+min);//最小值 //反转 //Collections.reverse(arr1); //System.out.println("反转后"+arr1); ///反转后[80, 100, 75, 3, 2, 1] //随机调换位置 // Collections.shuffle(arr1); // System.out.println("随机调换"+arr1); //指定调换位置 Collections.swap(arr1,3,1); System.out.println("交换后的"+arr1); //replaceALL(集he,oldval, newval) Collections.replaceAll(arr1,100,"张三"); System.out.println("替换后的"+arr1); ArrayList arr2 =new ArrayList(); arr2.add("张三"); int i =Collections.indexOfSubList(arr1,arr2); System.out.println("从前往后出现的第一个元素的下标"+i); int j =Collections.lastIndexOfSubList(arr1,arr2); System.out.println("从后往前出现的第一个元素的下标"+j); try{ Collection collection = Collections.unmodifiableCollection(arr2); collection.add("李四"); System.out.println(arr2); }catch (Exception e){ System.out.println("不能修改"+e); } } }
集合Conllections
最新推荐文章于 2024-10-06 20:16:20 发布