java.lang
Class String

java.lang.Object
  extended by java.lang.String
All Implemented Interfaces:
CharSequence

public final class String
extends Object
implements CharSequence

An immutable string of characters.


Constructor Summary
String(byte[] b)
          Create a String from a byte array
String(byte[] b, int off, int len)
          Create a String from a byte array
String(byte[] b, int off, int len, String charset)
          Create a String from a byte array
String(byte[] b, String charset)
          Create a String from a byte array
String(char[] c)
          Create a String from a character array
String(char[] c, int off, int len)
          Create a String from a character array.
 
Method Summary
 char charAt(int index)
          Return the character at the given index
 boolean equals(Object other)
          Compares the String with an Object
 boolean equalsIgnoreCase(String s)
           
 byte[] getBytes(String charset)
          Get bytes in US Acsii
 void getChars(int start, int end, char[] buffer, int off)
           
 int hashCode()
          Special version of hash that returns the same value the same String values
 int indexOf(int ch)
          Find the index of a character.
 int indexOf(int ch, int fromIndex)
          Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.
 int indexOf(String str)
          Finds the location of a string within this string
 int indexOf(String str, int fromIndex)
          Find location of String starting at a given index
 int lastIndexOf(String str)
          Find the last occurrence of a String
 int lastIndexOf(String str, int fromIndex)
          Find last occurrence of s string from a given index
 int length()
          Return the length of the String in characters
 CharSequence subSequence(int start, int end)
           
 String substring(int start)
          Return substring from starting position to the end of the String
 String substring(int start, int end)
          Return substring from starting index to position before end index
 char[] toCharArray()
          Converts the String into an array of characters
 String toLowerCase()
           
 String toString()
          Returns itself.
 String toUpperCase()
           
static String valueOf(boolean b)
           
static String valueOf(char c)
           
static String valueOf(char[] c)
           
static String valueOf(char[] c, int start, int length)
           
static String valueOf(double d)
           
static String valueOf(float f)
           
static String valueOf(int i)
           
static String valueOf(long i)
           
static String valueOf(Object aObj)
          Converts an Object to a String
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

String

public String(char[] c,
              int off,
              int len)
Create a String from a character array.

Parameters:
c - the character array
off - the offset - usually 0
len - the length of the String - must not be greater than c.length

String

public String(char[] c)
Create a String from a character array

Parameters:
c - the character array

String

public String(byte[] b)
Create a String from a byte array

Parameters:
b - the byte array

String

public String(byte[] b,
              int off,
              int len)
Create a String from a byte array

Parameters:
b - the byte array

String

public String(byte[] b,
              String charset)
Create a String from a byte array

Parameters:
b - the byte array
charset - ignored - assumed to be US ASCII

String

public String(byte[] b,
              int off,
              int len,
              String charset)
Create a String from a byte array

Parameters:
b - the byte array
charset - ignored - assumed to be US ASCII
Method Detail

length

public int length()
Return the length of the String in characters

Specified by:
length in interface CharSequence
Returns:
the length of the String

charAt

public char charAt(int index)
Return the character at the given index

Specified by:
charAt in interface CharSequence
Returns:
the characters at the given index

getChars

public void getChars(int start,
                     int end,
                     char[] buffer,
                     int off)

indexOf

public int indexOf(int ch)
Find the index of a character.

Parameters:
ch - The character to find.
Returns:
The index of the character. -1 means it wasn't found.

indexOf

public int indexOf(int ch,
                   int fromIndex)
Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index.

Parameters:
ch - a character (Unicode code point).
fromIndex - the index to start the search from.
Returns:
the index of the first occurrence of the character in the character sequence represented by this object that is greater than or equal to fromIndex, or -1 if the character does not occur.

indexOf

public int indexOf(String str)
Finds the location of a string within this string

Parameters:
str - the String
Returns:
Index of string location, -1 if string does not exist.

indexOf

public int indexOf(String str,
                   int fromIndex)
Find location of String starting at a given index

Parameters:
str - the String
fromIndex - the starting position
Returns:
Index of string location, -1 if string does not exist.

lastIndexOf

public int lastIndexOf(String str)
Find the last occurrence of a String

Parameters:
str - the String
Returns:
index of string location, -1 if string does not exist.

lastIndexOf

public int lastIndexOf(String str,
                       int fromIndex)
Find last occurrence of s string from a given index

Parameters:
str - the String
fromIndex - the starting point
Returns:
index of string location, -1 if string does not exist.

toCharArray

public char[] toCharArray()
Converts the String into an array of characters

Returns:
the character Array

substring

public String substring(int start)
Return substring from starting position to the end of the String

Parameters:
start - the starting position
Returns:
the substring

substring

public String substring(int start,
                        int end)
Return substring from starting index to position before end index

Parameters:
start - the start index
end - the end index (not included)
Returns:
the substring

subSequence

public CharSequence subSequence(int start,
                                int end)
Specified by:
subSequence in interface CharSequence

valueOf

public static String valueOf(Object aObj)
Converts an Object to a String

Returns:
the String that represents the object

toString

public String toString()
Returns itself.

Specified by:
toString in interface CharSequence
Overrides:
toString in class Object
Returns:
the String itself

equals

public boolean equals(Object other)
Compares the String with an Object

Overrides:
equals in class Object
Returns:
true if the String is equal to the object, false otherwise

equalsIgnoreCase

public boolean equalsIgnoreCase(String s)

toLowerCase

public String toLowerCase()

toUpperCase

public String toUpperCase()

hashCode

public int hashCode()
Special version of hash that returns the same value the same String values

Overrides:
hashCode in class Object

getBytes

public byte[] getBytes(String charset)
Get bytes in US Acsii

Parameters:
charset - ignored
Returns:
the ascii bytes

valueOf

public static String valueOf(boolean b)

valueOf

public static String valueOf(char c)

valueOf

public static String valueOf(char[] c)

valueOf

public static String valueOf(char[] c,
                             int start,
                             int length)

valueOf

public static String valueOf(double d)

valueOf

public static String valueOf(float f)

valueOf

public static String valueOf(int i)

valueOf

public static String valueOf(long i)