Search code examples
javahashmapjava-stream

Transform this into method that uses streams?


Do you know how should I transform this :

private static Map<Integer, EmptyTile> createAllPossibleEmpyTiles() {
 Map<Integer,EmptyTile> emptyTileMap = new HashMap<Integer, EmptyTile>();
        for (int i = 0; i <64 ; i++) {
            emptyTileMap.put(i,new EmptyTile(i));
        }
        return emptyTileMap;
}

?


Solution

  • one possibility to do this:

    Map<Integer, EmptyTile> emptyTileMap = IntStream.range(0, 64).boxed().collect(toMap(i -> i, EmptyTile::new));