前言
“金九银十”的秋招热潮已经开始了,经过7月8月这两个月的提前批,终于成功拿下了一些大厂的offer。小编经过这么多次的面试,这两天整理了一份面试清单分享给大家,希望能给大家一点帮助(java方向),觉得有帮助的同学可以转发点个赞哦~~
}
- Optional
用于处理对象空指针异常:
public String getDesc(Test test){
return Optional.ofNullable(test)
.map(Test::getDesc).else(“”);
}
JDK9
====
- 收集工厂方法
借助Java 9的一项新功能,即集合工厂方法,您可以轻松地使用预定义的数据创建不可变的集合。您只需要在特定集合类型上使用of方法。
List fruits = List.of(“apple”, “banana”, “orange”);
Map<Integer, String> numbers = Map.of(1, “one”, 2,“two”, 3, “three”);
在Java 9之前,您可以使用Collections,但这绝对是一种更复杂的方法。
public List fruits() {
List fruitsTmp = new ArrayList<>();
fruitsTmp.add(“apple”);
fruitsTmp.add(“banana”);
fruitsTmp.add(“orange”);
return Collections.unmodifiableList(fruitsTmp);
}
public Map<Integer, String> numbers() {
Map<Integer, String> numbersTmp = new HashMap<>();
numbersTmp.put(1, “one”);
numbersTmp.put(2, “two”);
numbersTmp.put(3, “three”);
return Collections.unmodifiableMap(nu