使用lambda表达式排序
Collections.sort(temp, (String a, String b) -> {return b.compareTo(a);});Collections.sort(temp, (String a, String b) -> b.compareTo(a));
Stream使用
List<String> test &#61; Arrays.asList("a", "a1", "a2", "b", "b1", "b2", "c", "c1", "ab");// 过滤test.stream().filter(s -> s.contains("a")).forEach(System.out::println);// 排序test.stream().sorted().forEach(System.out::println);// 映射test.stream().map(String::toUpperCase).forEach(System.out::println);// 匹配boolean a &#61; test.stream().allMatch(s -> s.contains("a"));boolean b &#61; test.stream().anyMatch(s -> s.contains("a"));boolean c &#61; test.stream().noneMatch(s -> s.contains("a"));System.out.println(a &#43; "," &#43; b &#43; "," &#43; c);// 计数long res &#61; test.stream().filter(s -> s.contains("a")).count();System.out.println(res);// 规约Optional<String> reduce &#61; test.stream().reduce((a1, a2) -> a1 &#43; "," &#43; a2);reduce.ifPresent(System.out::println);
Date
Clock clock &#61; Clock.systemDefaultZone();System.out.println(clock.millis());System.out.println(clock.instant());System.out.println(Date.from(clock.instant()));// 时区System.out.println(ZoneId.getAvailableZoneIds());ZoneId zone1 &#61; ZoneId.of("Asia/Aden");ZoneId zone2 &#61; ZoneId.of("Brazil/East");ZoneId zone3 &#61; ZoneId.of("Asia/Yerevan");System.out.println(zone1.getRules());System.out.println(zone2.getRules());System.out.println(zone3.getRules());LocalTime now1 &#61; LocalTime.now(zone1);LocalTime now2 &#61; LocalTime.now(zone2);LocalTime now &#61; LocalTime.now();System.out.println(now2 &#43; "," &#43; now1 &#43; "," &#43; now);LocalDate today &#61; LocalDate.now();System.out.println("today:"&#43;today);LocalDate tomorrow &#61; today.plus(1, ChronoUnit.DAYS);System.out.println(tomorrow);