Advertisement
Guest User

Untitled

a guest
Aug 28th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.94 KB | None | 0 0
  1.         public static class SortPairs {
  2.  
  3.                 private static int physical = 0;
  4.                 private static int words = 0;
  5.  
  6.                 public static void main(String[] args) {
  7.  
  8.                         // map to store
  9.                         Map<String, List<String>> map = new LinkedHashMap<String, List<String>>();
  10.  
  11.                         // create list one and two and store mixed
  12.                         List<String> words1    = new ArrayList<String>();
  13.                         List<String> physical1 = new ArrayList<String>();
  14.  
  15.                         physical1.add("ph1");
  16.                         words1.add("wor1");
  17.                         physical1.add("ph2");
  18.                         words1.add("wor2");
  19.                         physical1.add("ph3");
  20.                         words1.add("wor3");
  21.                         physical1.add("ph4");
  22.  
  23.                         map.put("A", words1);
  24.                         map.put("B", physical1);
  25.  
  26.                         ArrayList<List<String>> list = new ArrayList<>();
  27.  
  28.                         // iterate and display values
  29.                         System.out.println("Fetching multiple keys and corresponding values: ");
  30.                         for (Map.Entry<String, List<String>> entry : map.entrySet()) {
  31.                                 String key = entry.getKey();
  32.  
  33.                                 List<String> values = entry.getValue();
  34.  
  35.                                 list.add(values);
  36.                         }
  37.  
  38.                         int j = 0;
  39.                         while ( j < list.get(0).size() ) {
  40.  
  41.                                 int i = 0;
  42.                                 while ( i < list.size() ) {
  43.                                         System.out.println( list.get(i).get(j) );
  44.  
  45.                                         i++;
  46.                                 }
  47.  
  48.                                 j++;
  49.                         }
  50.                 }
  51.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement