I'm fairly new to Java8. I have a requirement to convert List of POJOs to group by a certain criteria and show it on UI.
- Convert list of objects that belong to Children category to Person category.
Return the List.
Children.java private String firstName; private String lastName; private String school; private String personId; // Setters and getters. Person.java private String fullName; private String address; // Setters and Getters. private Person convertChildToPerson(Children child) { Person person = new Person(); person.setFullName(child.getLastName() + ", " + child.getFirstName()); .. return person; }.. MAIN CODE.. ..
List<Person> personList; // Is populated by other functions. // Connect to DB and gets the output List<Children> childrenList = (Children) criteria.list(); for(Children children: childrenList) { personList.add(convertChildToPerson(children)); } return personList;Can't the FOR-LOOP present above be replaced by Java 8 Streams?