Friday 6 February 2015

Find count the number of occurrence of Strings in a Sentence?

Hint: input:this is String this is String output:[this 2 is 2 String 2] import java.util.*; public class FC { public static void main(String[] args) { HashMap<String,Integer> hm=new HashMap<String,Integer>(); for(String s:args) { if(hm.get(s)!=null) { int v=hm.get(s); v=v+1; hm.put(s,v); } else hm.put(s,1); } System.out.println(hm); } }

No comments:

Post a Comment