11/28/2011

Difference between String & StringBuilder


java.lang
Class String

java.lang.Object
  java.lang.String

public final class String extends Object implements Serializable, Comparable, CharSequence
 1.String objects are immutable
 2. String str = "abc"; is equivalent to: char data[] = {'a', 'b', 'c'};  String str = new String(data);
 3.Unicode Consortium's Unicode 3.0 specification.
 4.passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown.


Class StringBuilder
java.lang.Object
  java.lang.StringBuilder

  public final class StringBuilder extends Object implements Serializable, CharSequence

  1.A mutable sequence of characters. This class provides an API compatible with StringBuffer,
  2. but with no guarantee of synchronization.
  3.sb.append(); int no=sb.capacity();
  & Many Methods ..

  Always trim to the String it remove white spaces...
  :)