I have two lists. The insertion order into the "idOrderList" is also the sort order needed for the "idAndIndexList". I'm intersecting the list as below in the code.
{
List idOrderList; //insertion order in this list is sort order
List> idAndIndexList;
//List intersection is done as below
List resultList =
idOrderList.stream().filter(
new HashSet<>(idAndIndexList.stream()
.flatMap(o -> Stream.of(o.getLeft(),o.getRight()))
.collect(Collectors.toList()))::contains)
.collect(Collectors.toList());
}
I'm stuck at how to collect the "Pair.getRight()" into the "resultList" or alternately I want to collect the "idAndIndexList" Pair as result but maintain the insertion order of "idOrderList". Any input or suggestions. Many Thanks in advance
GS