途中、感受
Local 日期时间类
LocalDate localDate = LocalDate.now();
LocalTime localTime = LocalTime.now();
LocalDateTime localDateTime = LocalDateTime.now();
System.out.println(localDate);
System.out.println(localTime);
System.out.println(localDateTime);
Instant instant = Instant.now();
OffsetDateTime offsetDateTime = instant.atOffset(ZoneOffset.ofHours(8));
System.out.println(instant);
System.out.println(offsetDateTime);
Lambda表达式
Comparator<Integer> com1 = new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
return Integer.compare(o1, o2);
}
};
System.out.println(com1.compare(12,13));
System.out.println("===========");
// Lambda 表达式
Comparator<Integer> com2 = (o1, o2) -> Integer.compare(o1, o2);
System.out.println(com2.compare(12,13));
List<String> stringList = new ArrayList<>();
stringList.removeIf(str-> str.contains("aaa")); // 删除List中包含aaa的
// 方法引用
Comparator<Integer> com3 = Integer::compare;
System.out.println(com3.compare(12,13));
方法引用
类(或对象):: 方法名
对象 :: 非静态方法
类 :: 静态方法
类 :: 非静态方法
Consumer<String> con1 = str -> System.out.println(str);
con1.accept("北京");
Consumer<String> con2 = System.out::println;
con2.accept("北京");
Person person = new Person("张三", "23");
Supplier<String> supplier = () -> person.getName();
System.out.println(supplier.get());
Supplier<String> supplier1 = person::getName;
Function<Person, String> func3 = Person::getName;
System.out.println(supplier1.get());
Function<Double, Long> func = (o) -> Math.round(o);
func.apply(1.11);
Function<Double, Long> func1 = Math::round;
func1.apply(1.12);
Supplier<Person> func4 = () -> new Person();
Supplier<Person> func5 = Person::new; // new Person()
BiFunction<String, String, Person> fun6 = Person::new; // new Person(String name, String age)
Function<Integer, String[]> fun7 = String[]::new; // new String[Integer length]