I have a streaming input which has repeated values. I can use any data structure but I have to count the number of occurence of each element. Suppose I have a list of mobile phone suppliers like the following:
Apple Nokia Samsung Apple LG Nokia HTC Android Apple Nokia Nokia Apple Samsung
I have to build any data structure preferably a map with details like
Apple,4 Nokia,4 Samsung,2 LG,1 Android,1
I am not sure whether this is optimal. Is there a better solution than this?
In fact I have yet to write the above as a code. So better code will also help.
Yes, I would use a
Map<String, Integer>. I would wrap theaddin something like this:Or without generics: