Thanks @HadiJ for answer
Map<String,Integer> result = Arrays.stream(str)
.reduce(new HashMap<>(), (hashMap, e) -> {
hashMap.merge(e, 1, Integer::sum);
return hashMap;
},
(m, m2) -> {
m.putAll(m2);
return m;
}
);
More Related Contents:
- How to force max to return ALL maximum values in a Java Stream?
- Java 8 Nested (Multi level) group by
- How to convert a Java 8 Stream to an Array?
- Should I return a Collection or a Stream?
- What is difference between Collection.stream().forEach() and Collection.forEach()?
- How to sum a list of integers with java streams?
- Group by and sum objects like in SQL with Java lambdas?
- Why does Stream not implement Iterable?
- How can I create a stream from an array?
- In Java 8, is there a ByteStream class?
- Filter Java Stream to 1 and only 1 element
- Find maximum, minimum, sum and average of a list in Java 8
- Does Java SE 8 have Pairs or Tuples?
- Does Stream.forEach respect the encounter order of sequential streams?
- Java streams lazy vs fusion vs short-circuiting
- Collectors.summingInt() vs mapToInt().sum()
- How to check if a Java 8 Stream is empty?
- Stream Way to get index of first element matching boolean
- How to sum values in a Map with a stream?
- Is mapToDouble() really necessary for summing a List with Java 8 streams?
- Is it possible to cast a Stream in Java 8?
- In Java 8 how do I transform a Map to another Map using a lambda?
- Is it possible to get next element in the Stream?
- Does collect operation on Stream close the stream and underlying resources?
- How to get multiple values from an object using a single stream operation?
- Java8 Lambda: concat list [duplicate]
- non-interference requirement on Java 8 streams
- How to extract the dynamic values of the id attributes of the table elements using Selenium and Java
- Java 8 Stream and operation on arrays
- What is the difference between intermediate and terminal operations?