collections工具类

package com.com.collections;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class demo01 {
//不定参数
public static void chi(String...args){
for (String s:args){
System.out.println(s);
}
for (int i = 0; i < args.length ; i++) {
System.out.println(args[i]);
}
System.out.println(args.length);
}
public static void main(String[] args) {
chi("磺胺","木瓜");
List<Integer> list = new ArrayList<Integer>();
list.add(123);
list.add(1234);
list.add(1235);
list.add(123655);
Integer min = Collections.min(list);
System.out.println(min);
Integer max = Collections.max(list);
System.out.println(max);
//Collections中静态类 直接用//工具类
//sort是进行排序
Collections.sort(list);
System.out.println(list);
//shuffle是打乱一个列表
Collections.shuffle(list);
System.out.println(list);
Collections.addAll(list,44,5555,13);
System.out.println(list);

}
}
posted @ 2022-05-16 09:21  小松2739  阅读(25)  评论(0编辑  收藏  举报