title: CompareTo method in java acting weird
body: <p>I have an issue with the <code>compareTo</code> method in java, this is the code:</p>
  
  <pre><code>for(int i = 0; i &lt; btFolder.size(); i++) {
  
          String g = btFolder.get(i).toString();
  
          String[] subf = g.split(splitchar);
  
          String s = subf[subf.length-1].toUpperCase();
  
          if(s.compareTo(bt.toUpperCase()) == 0) {
              return g; 
          }
      }
      return null; //not found!
  </code></pre>
  
  <p>this will not jump into the <code>if-statement</code>, it should because the <code>s</code> and <code>bt</code> variables are equal, I know because I've done my homework and debugged it. Just to figure out what the <code>compareTo</code> method return I wrote this piece of code:</p>
  
  <pre><code>        String g = btFolder.get(i).toString();
  
          String[] subf = g.split(splitchar);
  
          String s = subf[subf.length-1].toUpperCase();
  
          String btUp = bt.toUpperCase();
  
          int theSame = s.compareTo(btUp);
  
          if(theSame == 0) {
             putSharedPrefs("pathToBt", g); 
          }
          return null; 
  </code></pre>
  
  <p>The variable <code>theSame</code> is 0, which means that <code>s</code> and <code>btUp</code> is equal. And still, <code>the if-statement</code> is never executed!  </p>
  
  <p>Why is this happening? Any good solutions to this? </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I've tried this too:</p>
  
  <pre><code>boolean equals = s.equalsIgnoreCase(bt);
  
          if(equals) {
              return g; 
          }
  </code></pre>
  
  <p>The <code>boolean</code> is <code>true</code>, but never excutes the <code>if-statement</code>, I should also mentioned that this is done inside a <code>thread</code>, but that should not cause any problem? </p>