How to group all the Objects in a List with the same Object property? Without mentioning the Object property value.
Model Class:
public class Item {
private String id;
private String name;
private String team
}
List<item> items = new ArrayList();
I have tried this:
items.stream().filter(item -> "Elites".equals(item.team)).collect(Collectors.toList());
But this requires passing the team name as a parameter.
How can we group the items without specifying a team value?
And Making a HashMap with Key as the item. team and value as a list of key-value pairs with that team.name & item.id
Like this:
"item.team":{
"item.id":"item.name",
"item.id":"item.name",
"item.id":"item.name",
.....
}
List, then I am not sure this is possible. Would it be feasible to transform theListinto aMap<String, List<Item>>, where the key is the type (asString) and the vallue is aListof allItems of this type?