Last active
November 28, 2015 19:53
-
-
Save thanoojgithub/4182e4fc708eac7b3356 to your computer and use it in GitHub Desktop.
Word Count
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.corejava | |
import java.util.Map; | |
import java.util.HashMap; | |
public class WordCount | |
{ | |
public static void main (String[] args) | |
{ | |
String str = "Today is a Holiday Day Today is a Working Day"; | |
String[] wordArray = str.split("\\s+"); | |
Map<String,Integer> map = new HashMap<String,Integer>(); | |
for(String w : wordArray){ | |
map.put(w, map.get(w) == null ? 1 : map.get(w)+1); | |
} | |
for(Map.Entry<String,Integer> entry : map.entrySet()){ | |
System.out.println(entry.getKey() + " | " + entry.getValue()); | |
} | |
} | |
} |
fixed compilation issues
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sample Word Count in java