{ List<Father> fatherList = new ArrayList<Father>(); // Create Father Object Father father = new Father(); father.setName("john"); father.setAge(25); List<Children> childrens = new ArrayList<Children>(); // Create child object Children children = new Children(); children.setName("david"); children.setAge(2); childrens.add(children); father.setChildrens(childrens); fatherList.add(father); fatherList.forEach(f -> { System.out.println("Father's Name : " + f.getName()); f.getChildrens().forEach(c -> { System.out.println("Children's Name : " + c.getName()); }); }); }
public static void main(String[] args) { List<Person> persons = Arrays.asList( new Person("John", new ChildrenListHolder(Arrays.asList(new Children("Lisa"), new Children("Jimmy")))), new Person("Clara", new ChildrenListHolder(Arrays.asList(new Children("Lisa"), new Children("Paul")))), new Person("George", new ChildrenListHolder(Arrays.asList(new Children("Paul")))) ); Map<String,List<Person>> map = persons.stream() .flatMap(p -> p.childrenListHolder.children.stream().map(c -> new AbstractMap.SimpleEntry<>(c, p))) .collect(Collectors.groupingBy( e -> e.getKey().childrensName, Collectors.mapping(Map.Entry::getValue, Collectors.toList()) )); System.out.println(map); }
def person = new Person(); person.personName = "Suganthan" def children = new Children() children.childrenName = "SuganthanchilName" def parent = new Parent() parent.parentName = "SuganthanParentName" def partner = new Partner() partner.partnerName = "SuganthanPartnerName" def sibling = new Sibiling() sibling.sibilingName = "SuganthanSibiligsName" person.addToChildrens(children) person.addToParents(parent) person.addToPartners(partner) person.addToSiblings(sibling) person.save()