1.optinal的应用
类似这样老代码:if(country != null && country.getCity() != null && country.getCity().getSchool() != null && country.getCity().getSchool().getStudent() != null .....) {
isValid = true;
}
新代码:boolean isValid = Optional.ofNullable(country)
.map(Country::getCity)
.map(City::getSchool)
.map(School::getStudent)
.isPresent();
2. for循环的遍历剩余节点,
// singel line
System.out.println("\n单行打印的解决方案");
Arrays.stream(names).iterator().forEachRemaining(name -> System.out.println(name));
3.
4.
5.
6.
7.