colleations工具类

时间:2021-08-23
本文章向大家介绍colleations工具类,主要包括colleations工具类使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
package WangGang01;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.stream.Collector;

public class Dome07 {
public static void main(String[] args) {
//Collection不支持创建对象,因为构造器私有化了
//Collections cols =new Collections();
//里面的属性和方法都是被static修饰,我们可以直接用类名,去调用即可
//常用方法
//addAll
ArrayList<String> strings = new ArrayList<>();
strings.add("bb");
strings.add("aa");
strings.add("cc");
Collections.addAll(strings,"dd","ee","ff");
Collections.addAll(strings,new String[]{"66","55","SD"});
System.out.println(strings);
Collections.sort(strings);//sort提供了一个升序的排列
System.out.println(strings);
//copy替换
ArrayList<String> strings1 = new ArrayList<>();
Collections.addAll(strings1,new String[]{"5","6"});
Collections.copy(strings,strings1);
System.out.println(strings);
System.out.println(strings1);
//fill填充
Collections.fill(strings,"666");
System.out.println(strings);
}
}

原文地址:https://www.cnblogs.com/java5745/p/15177405.html