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. Map<String, String[]> m = new HashMap<>();
  13. m.put("ISBN", new String[] { "I1", "I2", "I3", "I4" });
  14. m.put("Title", new String[] { "T1", "T2", "T3", "T4" });
  15. m.put("Price", new String[] { "P1", "P2", "P3", "P4" });
  16.  
  17. Set<String> keys = m.keySet();
  18. ArrayList<String[]> valuesArr = new ArrayList<>(m.values());
  19.  
  20. int i = 0;
  21. for (int j = 0; j < keys.size(); j++) {
  22. for (String key : keys) {
  23. for (String value : Arrays.copyOfRange(valuesArr.get(i), j, valuesArr.get(i).length)) {
  24. System.out.print(key + " : " + value + " ");
  25. i++;
  26. break;
  27. }
  28. }
  29. i=0;
  30. System.out.println();
  31. }
  32. }
  33. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
ISBN : I1 Price : P1 Title : T1 
ISBN : I2 Price : P2 Title : T2 
ISBN : I3 Price : P3 Title : T3