-3

I am new to LinkedHashMap and I want to put elements <String, Integer> in my Map with IntStream instead of filter.put("1", 1)... Is there any way to do it?

private Map<String, Integer> filter = new LinkedHashMap<>();

@PostConstruct
    public void init() throws IdNotFoundException {
        filter.put("1", 1);
        filter.put("2", 2);
        filter.put("3", 3);
        filter.put("4", 4);
        filter.put("5", 5);
        filter.put("6", 6);
        filter.put("7", 7);
        filter.put("8", 8);
        filter.put("9", 9);
        filter.put("10", 10);
        filter.put("All", -1);
    }

1 Answers1

2

To do so, I suggest to use IntStream:

 Map<String, Integer> filter = new LinkedHashMap<>();
    IntStream.range(1, 11).forEach(integer -> filter.put(String.valueOf(integer), integer));
    filter.put("All", -1);
Mustapha Belmokhtar
  • 1,231
  • 8
  • 21