Is there a built in Java method that takes several maps as arguments and returns a set of all keys in these maps?
Something like
public static Set<String> getKeys(Map<String, ?> ... arg2){
Set<String> result = new HashSet<>();
for (Map<String, ?> map : arg2) {
for (Map.Entry<String, ?> entry : map.entrySet()) {
String key = entry.getKey();
result.add(key);
}
}
return result;
}
Not that I know of, no. But let's have some fun with Java 8 streams, shall we?
private Set<String> keys(Map<String, ?>... maps) {
return Arrays.stream(maps).flatMap((map) -> map.keySet().stream()).collect(Collectors.toSet());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With