Java indexOf and lastIndexOf return -1?? Please Help
<p>In the following code, I am trying to check if an int (converted to String) contains duplicate digits. </p>

<pre><code>public static boolean hasDupes(int n)
  {
    String number = new String();
    number = Integer.toString(n);
    int digit = 0;
    System.out.println(num.indexOf(digit));
    System.out.println(num.lastIndexOf(digit));
    while(digit &lt; 10)
    {
      if(number.indexOf(digit) != number.lastIndexOf(digit))
      {
        return true; 
      }
      digit++;
    }
    //System.out.println(n);
    return false;
  }
</code></pre>

<p>I put in the <code>System.out.println</code> lines because I was unsure as to why my method wasn't working. They always print out '-1'. I dont understand how an index can be -1, and why it isn't working. </p>
