Collecting inner List from outer List using Java 8

398 views Asked by At

Let be Parent is a java class which contains normal primitive variables and an inner List and its corresponding getters and setters. Parent has a method getValue(index) which will return the list or field(corresponding getters).

Now I will get a List and to find out inner-inner-inner List. (3 level hierarchy). I will get the indexes from outside and I want to return innermost list.

Method:-

List<Parent> getList(int[] indexes, Parent parent)
 {

 int first = indexes[0];
 int second = indexes[1];
 int third = indexes[2];

 // Now I get the first inner List<Parent> by this code. 
 List<Parent> inner = (List<Parent>)  parent.getValue(first);

 // How will I get the remaining two lists from 'inner'
 }

How can I write the code in Java 8 using Lamdas and Streams.

0

There are 0 answers