fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String[] values= {"1","1","3","6","2"};
  11. Map<String,Integer> counts = new HashMap<String,Integer>();
  12. for (String s : values) {
  13. if (counts.containsKey(s)) {
  14. int old = counts.get(s);
  15. counts.put(s, old+1);
  16. } else {
  17. counts.put(s,1);
  18. }
  19. }
  20. for (Map.Entry<String,Integer> entry : counts.entrySet()) {
  21. System.out.println(entry.getKey() + " - " + entry.getValue());
  22. }
  23.  
  24. }
  25. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
3 - 1
2 - 1
1 - 2
6 - 1