title: java - how to compare string from construction through char[]
body: <p>I tried the following but could not get any answer to comparing 2 String.  How can I compare b and x and get 'true'?</p>
  
  <pre><code>import java.io.*;
  
  class Test {
    public static void main(String[] args) {
      // String a = "abc";
      String b = new String("abc");
      // System.out.printf("a == b -&gt; %b\n", (a == b));
      // System.out.printf("a.equals(b) -&gt; %b\n", a.equals(b));
      char[] x = new char[4];
      x[0] = 'a'; x[1] = 'b'; x[2] = 'c'; x[3] = 0;
      String s = new String(x);
      System.out.printf("x = %s\n", s);
      System.out.printf("b == s -&gt; %b\n", b == s);
      System.out.printf("b.equals(s) -&gt; %b\n", b.equals(s));
      System.out.printf("b.compareTo(s) -&gt; %d\n", b.compareTo(s));
    }
  }
  
  x = abc
  b == s -&gt; false
  b.equals(s) -&gt; false
  b.compareTo(s) -&gt; -1
  </code></pre>