title: Using Map<Integer,Integer> by taking the input from a user
body: <p>I have a question about Maps, from the type Integer,Integer. I made a mistake by solving a problem based on <code>&lt;Integer,Integer&gt;</code> map on <code>&lt;String,String&gt;</code>, the end result was correct however, the order of numbers was not descending. That would be solved if I chose <code>Integer</code> instead of <code>String</code>s.</p>
  
  <p>How can I take the input from the user and assign it to keys/values of my map when it is <code>Map&lt;Integer, Integer&gt;</code>? I used <code>substring()</code> and <code>indexOf()</code> to make my old map but for integers I couldn't find a way</p>
  
  <pre><code>import java.util.*;
  import java.io.*;
  import type.lib.*;
  
  public class MapTesting {
  public static void main(String[] args) {
      PrintStream output = new PrintStream(System.out);
      Scanner input = new Scanner(System.in);
  
      Map&lt;String,String&gt; normal = new HashMap&lt;String,String&gt;();
      output.println("Enter your map, one key-value pair per line,");
      output.println("comma-separated. Use empty line as sentinel.");
  
      for ( String entry = input.nextLine(); entry.length() !=0;
          entry = input.nextLine()) {
          int comma = entry.indexOf(",");
          String key = entry.substring(0,comma);
          String value = entry.substring(comma+1);
          normal.put(key,value);
      }
      output.println("The input map is:");
      output.println(normal);
  
      Map&lt;String,String&gt; reverse = new HashMap&lt;String,String&gt;();
      boolean distinct = true;
      for (Map.Entry&lt;String,String&gt; entry : normal.entrySet()) {
          String keyY = entry.getKey();
          String valueE = entry.getValue();
          String existingReverseValue = reverse.get(valueE);
  
          if (existingReverseValue != null) {
              int currentValue = Integer.parseInt(existingReverseValue);
              int potentialNewValue = Integer.parseInt(keyY);
              if ( potentialNewValue &lt; currentValue) {
                  reverse.put(valueE,keyY);
              }
          } else {
              reverse.put(valueE,keyY);
          }
      }
      output.println("The inverted map [using the smaller key as a tie breaker]:");
      output.println(reverse);
      }
  }
  </code></pre>