I have a list like this
List<Objeto> myList = new ArrayList<Objeto>();
Objeto o1 = new Objeto("1", "bbb");
myList.add(o1);
Objeto o2 = new Objeto("1", "rrrr");
myList.add(o2);
Objeto o3 = new Objeto("2", "eee");
myList.add(o3);
Objeto o4 = new Objeto("2", "wwww");
myList.add(o4);
Objeto o5 = new Objeto("3", "iiii");
myList.add(o5);
where Objecto is an object of this type
class Objeto{
private String contentId;
private String address;
Objeto(String id, String address){
this.contentId = id;
this.address = address;
}
//Getters and Setters
}
I want to merge the list into a HashMap like this
(1, {"bbb","rrrr"})
(2, {"eee","wwww"})
(3, {"iiii"})
Can I use a java 8 lambda to achieve it? Or though any other way?
Many thanks!