Strings

  • Enclosed in double quotes
  • + is the only overloaded operator. It is only overloaded for strings.
  • += is not overloaded.
  • String objects must be initialized when created.
  • When the compiler encounters a series of characters enclosed in double quotes, it creates a String object.
  • Neither String nor StringBuffer are a descendant of one another.

String

  • String objects are read-only.
String str1 = "alpha"; 
String str2 = new String("alpha");

Functions

  • boolean equals(String str)
  • boolean equalsIgnoreCase(String str)
  • int compareTo(String str)
  • int length()
  • char charAt(int index)
  • String substring(int beginIndex [, int endIndex])
  • int indexOf(String str [, int fromIndex])

StringBuffer

  • StringBuffer objects can be edited.
StringBuffer str1 = "beta";
StringBuffer str2 = new StringBuffer("beta");
StringBuffer str3 = new StringBuffer(50);

Functions

  • int length()
  • synchronized charAt(int index)
  • synchronized void setCharAt(int index, char ch)
  • synchronized StringBuffer append(TYPE arg)
  • synchronized StringBuffer insert(int offset, TYPE arg)