Facing error while converting a List<Object> to a HashMap<Key,Object>.
I can do with a traditional code, but I'm getting an error while doing using Java 8 streams and ignore the duplicate keys.
Equivalent code:
Map<String, Field> uniqueFields = new HashMap<>();
for (Field field : allFields) {
uniqueFields.put(field.getName(), field);
}
Tried below stream, but there's a syntactic mistake:
Map<String, Field> uniqueFields1 = allFields.stream()
.collect(Collectors.toMap(
Field::getName,
(oldValue, newValue) -> oldValue));