You can use this, but to be honest, your for loop is much more readable. I would try to avoid creating such a list in the first place and should have List<SomePair> , where SomePair contains the key and value.
List<Object> params = Arrays.asList("k1", "v1", "k2", "v2"); Map<String, Object> map = IntStream.range(0, params.size() / 2) .collect(HashMap::new, (m, i) -> m.put((String) params.get(i * 2), params.get(i * 2 + 1)), HashMap::putAll); System.out.println(map);
source share