title: Best way to Compare String of 10 numbers
body: <p>I'm comparing two Strings of min 8 digits and max 10 digits.  If 10 digits, will include two leading 0's.    </p>
  
  <p>Strings can be entered by user as either: </p>
  
  <p><code>String s1 = "0077889966";</code> </p>
  
  <p>or</p>
  
  <p><code>String s1 = "77889966";</code> </p>
  
  <p>String to compare should typically be in <code>"0077889966"</code> format as this is how they are stored on the object.</p>
  
  <p>What is the best way to compare two Strings of min 8 digits and max 10 digits?  </p>
  
  <p>I've tried converting to a number with <code>Integer.valueOf(s1)</code> however doesn't seem to be working correctly.  Not sure I should use <code>BigInteger</code> here or something else.  </p>
  
  <pre><code>String s1 = "0077889966";  // or "77889966" as input
  //Convert to number
  Integer num1 = Integer.valueOf(s1);
  
  //loop over Array of objects.  On match, print current object.
  for(int i = 0; i &lt; objs.length; i++) {
      String s2 = objs[i].getStringOfNum(); // "0088224477" 
      Integer num2 = Integer.valueOf(s2);
      if(num1 == num2){
      System.out.println(objs[i]);
  } else {
      System.out.println("no matches");
      }
  </code></pre>
  
  <p>Currently, I get all "no matches" in console.  There are as many "no matches" printed as there are objects in the Array. Nothing matches when at least one should so I question the precision of converting Strings into large numbers.</p>