java.lang
Class String

java.lang.Object
  extended by java.lang.String
All Implemented Interfaces:
CharSequence, Comparable<String>

public final class String
extends Object
implements CharSequence, Comparable<String>

An immutable string of characters.


Constructor Summary
String()
           
String(byte[] b)
          Create a String from a byte array
String(byte[] b, int hibyte)
          Deprecated.  
String(byte[] b, int off, int len)
          Create a String from a byte array
String(byte[] b, int hibyte, int off, int len)
          Deprecated.  
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.
String(int[] codePoints, int off, int len)
           
String(String s)
           
String(StringBuffer sb)
           
String(StringBuilder sb)
           
 
Method Summary
 char charAt(int index)
          Return the character at the given index
 int codePointAt(int index)
           
 int codePointBefore(int index)
           
 int codePointCount(int begin, int end)
           
 int compareTo(String str)
          Compares this with another Object.
 String concat(String s)
           
 boolean contentEquals(CharSequence s)
           
 boolean contentEquals(StringBuffer sb)
           
static String copyValueOf(char[] data)
           
static String copyValueOf(char[] data, int off, int len)
           
 boolean equals(Object other)
          Compares the String with an Object
 boolean equalsIgnoreCase(String s)
           
 byte[] getBytes()
           
 void getBytes(int begin, int end, byte[] dst, int off)
          Deprecated.  
 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
 String intern()
           
 boolean isEmpty()
          Returns true, if and only if this string is of zero length.
 int lastIndexOf(char ch)
           
 int lastIndexOf(char ch, int fromIndex)
           
 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
 int offsetByCodePoints(int idx, int codePointCount)
           
 String replace(char oldChar, char newChar)
           
 boolean startsWith(String s)
           
 boolean startsWith(String s, int begin)
           
 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()
           
 String trim()
           
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()

String

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

Parameters:
b - the byte array

String

@Deprecated
public String(byte[] b,
                         int hibyte)
Deprecated. 

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

@Deprecated
public String(byte[] b,
                         int hibyte,
                         int off,
                         int len)
Deprecated. 

Create a String from a byte array

Parameters:
b - the byte array

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

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(char[] c)
Create a String from a character array

Parameters:
c - the character array

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(int[] codePoints,
              int off,
              int len)

String

public String(String s)

String

public String(StringBuffer sb)

String

public String(StringBuilder sb)
Method Detail

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

codePointAt

public int codePointAt(int index)

codePointBefore

public int codePointBefore(int index)

codePointCount

public int codePointCount(int begin,
                          int end)

compareTo

public int compareTo(String str)
Description copied from interface: Comparable
Compares this with another Object. Returns -1 if this object is smaller, 0 if both objects are equal and 1 if this object is bigger.

Specified by:
compareTo in interface Comparable<String>
Parameters:
str - the object to compare with
Returns:
one of the values -1, 0, 1

concat

public String concat(String s)

contentEquals

public boolean contentEquals(CharSequence s)

contentEquals

public boolean contentEquals(StringBuffer sb)

copyValueOf

public static String copyValueOf(char[] data)

copyValueOf

public static String copyValueOf(char[] data,
                                 int off,
                                 int len)

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)

getBytes

public byte[] getBytes()

getBytes

@Deprecated
public void getBytes(int begin,
                                int end,
                                byte[] dst,
                                int off)
Deprecated. 


getBytes

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

Parameters:
charset - ignored
Returns:
the ascii bytes

getChars

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

hashCode

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

Overrides:
hashCode in class Object

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.

intern

public String intern()

isEmpty

public boolean isEmpty()
Returns true, if and only if this string is of zero length.

Returns:
true if this string is of zero length, false otherwise.

lastIndexOf

public int lastIndexOf(char ch)

lastIndexOf

public int lastIndexOf(char ch,
                       int fromIndex)

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.

length

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

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

offsetByCodePoints

public int offsetByCodePoints(int idx,
                              int codePointCount)

replace

public String replace(char oldChar,
                      char newChar)

startsWith

public boolean startsWith(String s)

startsWith

public boolean startsWith(String s,
                          int begin)

subSequence

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

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

toCharArray

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

Returns:
the character Array

toLowerCase

public String toLowerCase()

toUpperCase

public String toUpperCase()

toString

public String toString()
Returns itself.

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

trim

public String trim()

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)

valueOf

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

Returns:
the String that represents the object