I have a HashMap which contains a key: String ( name of object be instantiated ) and Value: List ( variables for the instantiated object)
My current method :
public Map<Room,List<String>> buildRoomObjects(Map<String,List<String>> map){
List<Room> rooms = map.keySet().stream().map(Room::new).collect(Collectors.toList());
Map<Room,List<String>> newmap = new HashMap<>();
for ( Room room : rooms){
newmap.put(room,map.get(room.getName()));
}
return newmap;
}
Can I avoid the use of the enhanced for Loop here and condense to a single stream?