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. // your code goes here
  13. Map<String, List<String>> map = new HashMap<String, List<String>>();
  14.  
  15. // create list one and store values
  16. List<String> l1 = new ArrayList<String>();
  17. l1.add("Apple");
  18. l1.add("America");
  19.  
  20. // create list two and store values
  21. List<String> l2 = new ArrayList<String>();
  22. l2.add("Bat");
  23. l2.add("Bangladesh");
  24.  
  25. // create list three and store values
  26. List<String> l3 = new ArrayList<String>();
  27. l3.add("Cat");
  28. l3.add("China");
  29.  
  30. // put values into map
  31. map.put("A", l1);
  32. map.put("B", l2);
  33. map.put("C", l3);
  34.  
  35. // iterate and display values
  36. System.out.println("Fetching Keys and corresponding MULTIPLE Values n");
  37. for (Map.Entry<String, List<String>> entry : map.entrySet())
  38. {
  39. String key = entry.getKey();
  40. List<String> values = entry.getValue();
  41. System.out.println("Key = " + key);
  42. System.out.println("Values = " + values + "\n");
  43. }
  44. }
  45.  
  46.  
  47. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
Fetching Keys and corresponding MULTIPLE Values n
Key = A
Values = [Apple, America]

Key = B
Values = [Bat, Bangladesh]

Key = C
Values = [Cat, China]