String Class

The String class represents an immutable string: Once an instance is created, the string it contains cannot be changed. There are numerous forms of constructor, allowing you to build an instance out of an array of bytes or chars, a subset of an array of bytes or chars, another string, or a string buffer. It is important to realize that you can change the String object pointed to by a String handle, BUT YOU CANNOT CHANGE THE VALUE OF A STRING OBJECT!!!
Creating Strings: You could create a String handle and object with:
     String s1 = new String("Tornadoes");
  OR you could accomplish the same goal with:
     String s1 = "Tornadoes";

---------------------------------------
Comparing Strings: There are two types of comparisons you might want to perform with Strings. First, you can test to see if two String handles point to the same object. This is done using == as in:

      s1==s2
  Second, you can test to see if the underlying objects 
  contain equivalent strings as in:
      s1.equals(s2)
Obviously, since Strings are immutable, if two String handles point to the same underlying object, then s1.equals(s2) will have to be true!
---------------------------------------
String Class Methods: The String class contains a bunch of methods to help you do all sorts of useful things with Strings:
char charAt(int index)Returns the indexed character of a string, where the index of the initial character is 0.
String concat(String addThis)Returns a new string consisting of the old string followed by addThis.
int compareTo(String otherString)Performs a lexical comparison; returns an int that is less than 0 if the current string is less than otherString, equal to 0 if the strings are identical, and greater than 0 if the current string is greater than otherString
boolean endsWith(String suffix).Returns true if the current string ends with suffix, otherwise returns false
boolean equals(Object ob)Returns true if ob instanceof String, and the string encapsulated by ob matches the string encapsulated by the executing object.
boolean equalsIgnoreCase(String s)Is like equals(), but the argument is a String, and the comparison ignores case.
int indexOf(char ch)Returns the index within the current string of the first occurrence of ch. Alternative forms return the index of a string, and begin searching from a specified offset.
int lastIndexOf(char ch)Returns the index within the current string of the last occurrence of ch. Alternative forms return the index of a string, and end searching at a specified offset from the end of the string.
int length()Returns the number of characters in the current string.
replace(char oldChar, char newChar)Returns a new string, generated by replacing every occurrence of oldChar with newChar.
boolean startsWith(String prefix)Returns true if the current string begins with suffix, otherwise returns false.
String substring(int startIndex)Returns the substring, beginning at startIndex, of the current string and extending to the end of the current string. An alternate form specifies starting and ending offsets.
String toLowerCase()Converts the executing object to lower case and returns a new string.
String toString()Returns the executing object.
String toUpperCase()Converts the executing object to upper case and returns a new string.
String trim()Returns the string that results from removing whitespace characters from the beginning and ending of the current string.

---------------------------------------
Using The Replace Method: As an example of how to use String methods, the following example shows how to use the replace method:
To run this example type:
    java re
At the command line.
---------------------------------------
Sorting Using String Methods:
To run this example type, for instance,
  java sort boy girl zoo cat dog ant house
at the command line.
---------------------------------------