i am have problem. Actually i am working on some code and that code is written in python but i want to do same problem in java .i got everything but on collection some problem is coming.
i am storing values in dictionary in java :
Dictionary<String, Integer> dc=new Hashtable<String, Integer>();
String s[]={"red", "blue", "red", "green", "blue", "blue"};
for(String t: s){
if(dc.get(t)==null)
dc.put(t, 1);
else
dc.put(t, dc.get(t)+1);
}
output:
{blue=3, green=1, red=2}
i want like:
{blue=3, red=2, green=1}
but this is not the output i want i want like python gave:
cnt = Counter()
>>> for word in ['red', 'blue', 'red', 'green', 'blue', 'blue']:
... cnt[word] += 1
>>> cnt
Counter({'blue': 3, 'red': 2, 'green': 1})
can any one give me some idea ?