java hashmap集合如何最优的去除value为null或空的元素
无非就是遍历了,基本都得O(n)吧
Map<String,Object> map=new HashMap<>();
map.put("1",null);
map.put("2",null);
map.put("3",null);
map.put("4",null);
map.put("5",null);
Map<String, Object> newMap = map.entrySet().stream().filter((e) -> e.getValue() != null).collect(Collectors.toMap(
(e) -> (String) e.getKey(),
(e) -> e.getValue()));
除了keySet还有更快的吗?
问答版主就是牛,从现在起只回论坛,不在踏入问答半步