I have an object that looks like this
class MyObject { String type; List<String> subTypes; }
Is it possible, given the MyObject list, to use Java 8 threads to filter both type and subtype?
I still have
myObjects.stream() .filter(t -> t.getType().equals(someotherType) .collect(Collections.toList());
but inside this I also want each subtype to have another filter that also filters them by a specific subtype. I canβt figure out how to do this.
An example would be
myObject { type: A, subTypes [ { X, Y, Z } ] } myObject { type: B, subTypes [ { W, X, Y } ] } myObject { type: B, subTypes [ { W, X, Z } ] } myObject { type: C, subTypes [ { W, X, Z } ] }
I would go into matchType B and subType Z, so I would expect a single result -> myObject of type B, subtypes: W, X, Z
the following currently returns 2 items in the list.
myObjects.stream() .filter(t -> t.getType().equals("B") .collect(Collections.toList());
but I would like to add an additional filter for each of the subtypes and only combine where "Z" is present.
java java-8
Simon Kent
source share