Étiquette : Lambdas

Let input be a List of String, you want it to become Map<String, String> where even elements are the keys, and odd elements are the values. Works only when key elements are unique. Map<String, String> mappedValues = input.stream().collect(Collectors.toMap( Function.identity(), input::indexOf)).entrySet().stream().collect(Collectors.toMap( entry -> {return entry.getKey();}, entry -> {return entry.getValue() == input.size() − 1 ? −1 :… Read More »