java.lang
Class String

java.lang.Object
  |
  +--java.lang.String

public class String
extends Object

The String class represents strings of characters.


Constructor Summary
String()
          Create a new String of zero length.
String(char[] data)
          Create a new String that is a copy of an array of characters.
String(String value)
          Create a new String that is a copy of the parameter value.
String(StringBuffer str)
          Create a new String from a StringBuffer.
 
Method Summary
 char charAt(int index)
          Return the character at the specified offset from the start of the String.
 boolean equals(String anotherString)
          Test the string with equality with another string.
 boolean equalsIgnoreCase(String anotherString)
          Perform a case-insensitive comparison this string and another string.
 int indexOf(String str)
          Finds the first occurance of the specified String in this String.
 int length()
          Return the length of this String measured in characters.
 void setCharArray(char[] a)
          Specify the array that should be used to hold the characters in the string.
 char[] toCharArray()
          Return the character array containing the characters in the string.
 String toString()
          Return a reference to this String.
static String valueOf(int i)
          Create a new string which is the decimal value of an integer.
static String valueOf(int i, String val)
          Convert an integer into a string and place the result into an existing string.
 
Methods inherited from class java.lang.Object
equals
 

Constructor Detail

String

public String()
Create a new String of zero length.

String

public String(String value)
Create a new String that is a copy of the parameter value.
Parameters:
value - the String to make a copy of.

String

public String(char[] data)
Create a new String that is a copy of an array of characters. The array of characters is copied, so that any changes to the array are not reflected in the new string.
Parameters:
data - the array of characters to make into a string.

String

public String(StringBuffer str)
Create a new String from a StringBuffer.
Parameters:
str - the StringBuffer to copy into the new String.
Method Detail

toString

public String toString()
Return a reference to this String.
Returns:
a reference to this String.

length

public int length()
Return the length of this String measured in characters.
Returns:
length of the String.

charAt

public char charAt(int index)
            throws IndexOutOfBoundsException
Return the character at the specified offset from the start of the String. An index of zero refers to the first character in the string.
Parameters:
index - offset into the String.
Returns:
the character at the specified offset into the String.

toCharArray

public char[] toCharArray()
Return the character array containing the characters in the string. Note that this array is a reference, not a copy, of the string data so any changes to the characters will result in a change to the original string.
Returns:
the character array containing the string.

setCharArray

public void setCharArray(char[] a)
Specify the array that should be used to hold the characters in the string.
Parameters:
a - an array of characters that should replace the current string.

valueOf

public static String valueOf(int i)
Create a new string which is the decimal value of an integer.

Note that this method will allocate memory for a new string.

Parameters:
i - integer to convert to a string.

valueOf

public static String valueOf(int i,
                             String val)
Convert an integer into a string and place the result into an existing string.
Parameters:
i - integer to convert to a string.
val - string to store the result in. val must be long enough to store the string value of i.

equals

public boolean equals(String anotherString)
Test the string with equality with another string. The comparison is performed respecting case.
Parameters:
anotherString - the string to compare with this string.

equalsIgnoreCase

public boolean equalsIgnoreCase(String anotherString)
Perform a case-insensitive comparison this string and another string.
Parameters:
anotherString - the string to compare with this string.

indexOf

public int indexOf(String str)
Finds the first occurance of the specified String in this String.
Parameters:
str - the String to search for.
Returns:
the index of the first character matching the String or -1 if the String is not found.