Collections.addAll(单值类型集合,元素1,元素2,元素3);
Collections.sort(list集合);
Collections.sort(list集合,比较器对象)
Collections.reverse(list集合);
让线程不安全的变成安全的: synchronizedList
Collections.synchronizedList(list集合);
Collections.synchornizedSet(set集合);
Collections.synchronizedSortedSet(sortedSet集合);
Collections.sycchronizedCollection(collection集合);
package com.atguigu.java8;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class TestLambdaplus {
List<Employee> emps= Arrays.asList(
new Employee(101, "张三", 18, 9999.99),
new Employee(102, "李四", 59, 6666.66),
new Employee(103, "王五", 28, 3333.33),
new Employee(104, "赵六", 28, 7777.77),
new Employee(105, "田七", 38, 5555.55)
);
@Test
public void test1(){
Collections.sort(emps,(e1,e2)->{
if(e1.getAge()==e2.getAge()) {
return e1.getName().compareTo(e2.getName());
}else {
return Integer.compare(e1.getAge(),e2.getAge());
}
}
);
emps.stream().forEach(System.out::println);
}
}