I have a HashMap with the following structure:
Map<Object, List<OtherObject>>
And I want to convert it to:
List<FinalObject>
being FinalObject:
public class FinalObject {
private Object object;
private List<OtherObject> otherObject;
}
Assuming you have a constructor like:
public FinalObject(Object obj, List<OtherObject> list) {
this.object = obj;
this.otherObject = list;
}
then you can do:
List<FinalObject> newList = map.entrySet()
.stream().map(e -> new FinalObject(e.getKey(), e.getValue()))
.collect(Collectors.toList());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With