title: Java: Selection sort of String array
body: <p>I am working on some sort algorithms for a school project and i have a problem .
  The following code its not sorting the array,I have tried the same code with array of numbers(the only change is in the if) and it was working but now with the String array and the use of compareTo its not working its just puts the items in "random" order.</p>
  
  <pre><code>public static void selectionSortISBN(Book pin[], int booksCounter) {
      for (int x = 0; x &lt; booksCounter; x++) {
          int minIndex = x;
          for (int y = x + 1; y &lt; booksCounter; y++) {
              if (pin[y].getISBN().compareTo(pin[minIndex].getISBN()) &lt; 0) {
                  minIndex = y;
              }
          }
          Book temp = pin[x];
          pin[x] = pin[minIndex];
          pin[minIndex] = temp;
      }
  }
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I changed my inner for to this :</p>
  
  <pre><code>        for (int y = x + 1; y &lt; booksCounter; y++) {
              int com=pin[y].getISBN().compareTo(pin[minIndex].getISBN());
              System.out.println(pin[y].getISBN()+"   "+pin[minIndex].getISBN()+"  =   "+com);
          }
  </code></pre>
  
  <p>and the output i am getting is this </p>
  
  <pre><code>1537   1485  =   1
  596   1485  =   4
  1164   1485  =   -3
  909   1485  =   8
  596   1537  =   4
  1164   1537  =   -4
  909   1537  =   8
  1164   596  =   -4
  909   596  =   4
  909   1164  =   8
  </code></pre>