How can we convert List<LinkedHashMap> in to List of Custom Object (List<Employee>) using Java 8 Streams.
Example : List<LinkedHashMap>
Here name and designation both are LinkedHashmap key. if you copy below snippet in IDE you can have better understand of this List<LinkedHashMap>.
List<LinkedHashMap> list = new ArrayList<>();
LinkedHashMap<String, String> linkedHashMap1 = new LinkedHashMap<>((Map.of("name","David", "designation","Senior Software Engineer")));
LinkedHashMap<String, String> linkedHashMap2 = new LinkedHashMap<>((Map.of("name","Alex", "designation","Software Engineer")));
LinkedHashMap<String, String> linkedHashMap3 = new LinkedHashMap<>((Map.of("name","Jessi","designation","Lead")));
LinkedHashMap<String, String> linkedHashMap4 = new LinkedHashMap<>((Map.of("name","Martin","designation","Manager")));
list.add(linkedHashMap1);
list.add(linkedHashMap2);
list.add(linkedHashMap3);
list.add(linkedHashMap4);
System.out.println(list);
Need to convert above List<LinkedHashmap> to List<Employee> Where Employee class has below two fields :
Class Employee {
String name;
String designation;
}
Expected output :
[Employee(name = David, designation = Senior Software Engineer),
Employee(name = Alex, designation = Software Engineer),
Employee(name = Jessi, designation = Lead),
Employee(name = Martin, designation = Manager)]