java8新特性
文章平均质量分 73
qimeng_1122
这个作者很懒,什么都没留下…
展开
-
Optional
看一个比较复杂的例子。 假如我们需要的数据层次比较深。 String cityCode = customer.getAddress().getCity().getCityCode().substring(0,3); 这样获取是不合理的,因为其中的某一环,可能是空,会抛出空指针的。所以,我们需要一层层的进行判断。 public void getCityCode(Customer customer) { String cityCode = "000"; if (customer != null转载 2020-12-28 10:00:21 · 85 阅读 · 0 评论 -
Stream
对map进行排序 //根据num大小排序,将num值转为String List<HashMap<String, String>> orderList = dataList.stream() //先根据num-Integer类型排序 .sorted((a, b) -> b.get("num").compareTo(a.get("num"))) //排序之原创 2020-12-28 11:17:57 · 91 阅读 · 0 评论