Java List<String> to Map<String, Integer> convertion
问题 I'd like to convert a Map <String, Integer> from List<String> in java 8 something like this: Map<String, Integer> namesMap = names.stream().collect(Collectors.toMap(name -> name, 0)); because I have a list of Strings, and I'd like to to create a Map, where the key is the string of the list, and the value is Integer (a zero). My goal is, to counting the elements of String list (later in my code). I know it is easy to convert it, in the "old" way; Map<String,Integer> namesMap = new HasMap<>();