title: Java - How to Loop and Print Values From 2 HashMaps on the Same Line?
body: <p>I found related questions but I'm not sure how to do this using a for loop. I have two HashMaps that are filled by user input. Both maps have matching keys. I'm trying to come up with a final report that would pull the matching key and the values for each individual map, all printed on the same line. As of right now, my code is printing the first HashmMap(Products) followed by the values second MashMap(Price).</p>
  
  <p>Current Output</p>
  
  <pre><code>Priority Product  Price
  
  1 apple  
  2 banana   
  3 orange  
  $ 43.81   
  $ 69.64   
  $ 96.35  
  </code></pre>
  
  <p>I thought about creating a 3rd hashmap and combining all values into one, but I'm not sure if that will really work. </p>
  
  <p>Desired Output</p>
  
  <pre><code>Priority Product Price
  
  1 apple  $ 43.81  
  2 banana $ 69.64   
  3 orange $ 96.35  
  </code></pre>
  
  <p>My Code  </p>
  
  <pre><code>import java.util.*; 
  
  
  public class Testing 
  {
  
      String products;
      int priority;
      double price; 
  
  
      Scanner keyboard = new Scanner(System.in); //Scanner 
  
      HashMap&lt;Integer, String&gt; pMap = new HashMap&lt;Integer, String&gt;(); // Product HashMap
  
      HashMap&lt;Integer, Double&gt; priceMap = new HashMap&lt;Integer, Double&gt;(); //Price HashMap
  
      Random r = new Random(); //Random number
  
  
      public void testingItems()
      {
  
  
          for ( int count = 0; count &lt; 3; count++)
              {
                  //Ask for user input to Add product name and product priority 
  
                      System.out.println("\nEnter a Product"); 
                      products = keyboard.nextLine();
  
  
                      System.out.println("\nEnter a Priority");
                      priority = keyboard.nextInt();
  
                      price = (r.nextDouble() * 100); 
                      //System.out.print(price);
  
  
                      keyboard.nextLine(); 
  
  
                  //*** HASHMAPS *** 
  
                      //Add product and priority to HashMap 
  
  
  
                      pMap.put(priority, products);
  
                      priceMap.put(priority, price); 
  
  
  
                      System.out.println("Product: "+ products + "\t\t" + "Priority: " +  priority + "\n\n" + "Price:" + " $ "+ price);
              }
  
  
                      System.out.println("\nPriority  " + "  Product  " + "  Price");
                      System.out.println("----------------------------------------");
  
                      for (Integer key: pMap.keySet())
                      {                                                                                   
                          System.out.println(key + "\t" + pMap.get(key));
                      }
                          for (Integer key2: priceMap.keySet()){
                              System.out.println("$ " + priceMap.get(key2));
                          }
  
              }
      }
  </code></pre>