首页 > 其他 > 详细

colleations工具类

时间:2021-08-23 22:58:45      阅读:23      评论:0      收藏:0      [点我收藏+]
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);
}
}

colleations工具类

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!