I've got a problem.
I've got a big Java list of String (about 100K of entry) that contains events name.
It is like this:
List<String> myList = new ArrayList<>();
myList.add("eventB");
myList.add("eventB");
myList.add("eventA");
myList.add("eventB");
myList.add("eventA");
myList.add("eventA");
myList.add("eventA");
myList.add("eventB");
myList.add("eventB");
myList.add("eventC");
myList.add("eventD");
myList.add("eventC");
...
I need a way to count the occurrences of every event, select the top 1000 events and their occurrences. I don't know all the event's name... I've got about 1000 different event name..
My output should be like this:
___
_________________ |
| EventName | # | |
|___________|_____| |
| eventB | 609 | |
| eventC | 542 | |
| eventD | 540 | |
| eventA | 463 | \ top 1000
| . | . | / entry
| . | . | |
| . | . | |
| eventN | 123 | |
|___________|_____| |
___|
i need the String of eventName and the Integer of the occurrences (#). (after i 'll put them into a HTML table of a web-application)
i try in this way:
Map<String,Integer> myMap = new HashMap<String, Integer>();
for(String evnt : myList){
if(!myMap.containsKey(evnt))
myMap.put(evnt,1);
else{
myMap.put(evnt, myMap.get(evnt)+1);
}
}
But now i don't know how sort it..