I don't know why does not work with me. I have a empty keys in map but I cannot catch them.
Map<String, Long> map = new TreeMap<>();
//put data
map.entrySet().stream().forEach(e -> {
if (e.getKey().equals("") || e.getKey().equals(" ") || e.getKey() == "" || e.getKey() == " ") {
map.remove(e.getKey(), e.getValue());
}
});
Edited: I made a test for value:
map.entrySet().stream() .forEach(e -> {
if (e.getValue() == 133835) {
System.out.println("key empty: " + e.getKey().isEmpty());
System.out.println("key: >" + e.getKey() + "<");
System.out.println("val: " + e.getValue());
}
});
map = map.entrySet().stream().filter(
p -> !"".equals(p.getKey().trim())).
collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
map.entrySet().stream() .forEach(e -> {
if (e.getValue() == 133835) {
System.out.println("key empty: " + e.getKey().isEmpty());
System.out.println("key: >" + e.getKey() + "<");
System.out.println("val: " + e.getValue());
}
});
the result is:
key empty: false
key: ><
val: 133835
key empty: false
key: ><
val: 133835
I think this key is a gost )