fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String[] city = {"texas", "ny", "sydney", "ny", "paris", "texas", "ny",
  13. "texas", "ny", "sydney", "ny", "paris", "texas", "ny"};
  14. List<String> asList = Arrays.asList(city);
  15. Map<String, Integer> map= new HashMap<String, Integer>();
  16. for(String s: city){
  17. map.put(s,Collections.frequency(asList,s));
  18. }
  19. System.out.println(map);
  20. }
  21. }
Success #stdin #stdout 0.11s 320512KB
stdin
Standard input is empty
stdout
{sydney=2, paris=2, texas=4, ny=6}