package com.msb.test01;标签:ArrayList,list,System,list2,Collections,工具,out From: https://www.cnblogs.com/jeldp/p/16888975.html
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
/**
* @author : liu
* 日期:14:02:08
* 描述:IntelliJ IDEA
* 版本:1.0
*/
public class Test04 {
//这是一个main方法:是程序的入口
public static void main(String[] args) {
//Collections不支持创建对象,因为构造器私有化了
//Collections c=new Collections();
//里面的属性方法都是被STATIC修饰,我们直接可以类名。去调用
//常用方法:
//addALL:
ArrayList<String> list=new ArrayList<>();
list.add("aa");
list.add("dd");
list.add("bb");
list.add("cc");
Collections.addAll(list,"ee","ff","ff");
Collections.addAll(list,new String[]{"ee","ff","ff"});
System.out.println(list);
//binarySearch必须在有序的集合中查找
//binarySearch
Collections.sort(list);//sort提供的是升序排序
System.out.println(Collections.binarySearch(list, "cc"));
//copy:替换方法
ArrayList<String> list2=new ArrayList<>();
Collections.addAll(list2,"tt","ss");
Collections.copy(list,list2);//将list2的内容替换到list上去
System.out.println(list);
System.out.println(list2);
//fill填充
Collections.fill(list2,"yyy");
System.out.println(list2);
}
}