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. private static HashMap<String, HashMap<String, ArrayList>> parentMap = new HashMap<>();
  11.  
  12. public static ArrayList<String> getMap(String parentkey, String childKey) {
  13. return parentMap.get(parentkey).get(childKey);
  14. }
  15.  
  16.  
  17. public static ArrayList<String> setMap(String parentkey, String childKey, String value) {
  18. parentMap.computeIfAbsent(parentkey, k->new HashMap<>());
  19. HashMap<String, ArrayList> childMap = parentMap.get(parentkey);
  20. childMap.computeIfAbsent(childKey, k -> new ArrayList<>()).add(value);
  21. return getMap(parentkey, childKey);
  22. }
  23.  
  24. public static void main(String[] args) {
  25. setMap("India", "EmployeeName", "A");
  26. setMap("India", "EmployeeName", "B");
  27. setMap("India", "EmployeeName", "C");
  28. setMap("China", "EmployeeName", "D");
  29. setMap("China", "EmployeeName", "E");
  30. setMap("China", "EmployeeName", "F");
  31. System.out.println("India" + getMap("India", "EmployeeName"));
  32. System.out.println("China" + getMap("China", "EmployeeName"));
  33. }
  34. }
Success #stdin #stdout 0.12s 50256KB
stdin
Standard input is empty
stdout
India[A, B, C]
China[D, E, F]