集合Conllections

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);
}
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值