List<String> s = new ArrayList<>();
System.out.println(Preconditions.checkElementIndex(2,s.size(),"下标长度超过了"));
是否为空
java复制代码
String s = null;
System.out.println(Preconditions.checkNotNull(s));
判空和多个参数hashcode
java复制代码
String s = null;
if (Objects.equal(null, s)) {
System.out.println("为null");
return;
}
//计算多个参数的hashcode
int i = Objects.hashCode("123", "222");
System.out.println(i);
java复制代码
Ordering<Comparable> natural = Ordering.natural();
List<LocalDateTime> list = new ArrayList<>(Arrays.asList(LocalDateTime.parse("2022-11-12T10:20:30"), LocalDateTime.parse("2021-11-12T10:20:21"), LocalDateTime.parse("2021-11-12T10:21:30")));
list.sort(natural);
list.stream().forEach(e -> {
System.out.println(e);
});