Sample output All Is Well : { =2, A=1, s=1, e=1, W=1, I=1, l=4}
Asked
Active
Viewed 239 times
0
-
Can you share what you tried? – Eran Jan 24 '22 at 13:42
-
I know how to do it in normal way like using map but using lambda or streams (java-8) I don't have idea – JAVA LOVER Jan 24 '22 at 14:26
-
Duplicate of https://stackoverflow.com/q/70224399/160256 – Keegan Jan 25 '22 at 02:33
1 Answers
0
You may try this,
Arrays.stream("inputstring".split(""))
.map(String::toLowerCase)
.collect(Collectors.groupingBy(s -> s, LinkedHashMap::new, Collectors.counting()))
.forEach((k, v) -> System.out.println(k + " = " + v));
VenkatN
- 1
-
Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 04 '22 at 22:58