|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.String
A general class of objects to represent character Strings. Strings are constant, their values cannot be changed after creation. The compiler makes sure that each String constant actually results in a String object. Because String objects are immutable they can be shared. For example:
String str = "abc";is equivalent to:
char data[] = {'a', 'b', 'c'}; String str = new String(data);Here are some more examples of how strings can be used:
System.out.println("abc"); String cde = "cde"; System.out.println("abc" + cde); String c = "abc".substring(2,3); String d = cde.substring(1, 2);
StringBuffer
Constructor Summary | |
String()
Constructs a new empty String. |
|
String(byte[] ascii,
int hibyte)
Constructs a new String whose value is the specified array of bytes. |
|
String(byte[] ascii,
int hibyte,
int offset,
int count)
Constructs a new String whose initial value is the specified subarray of bytes. |
|
String(char[] value)
Constructs a new String whose initial value is the specified array of characters. |
|
String(char[] value,
int offset,
int count)
Constructs a new String whose initial value is the specified sub array of characters. |
|
String(String value)
Constructs a new String that is a copy of the specified String. |
|
String(StringBuffer buffer)
Construct a new string whose value is the current contents of the given string buffer |
Method Summary | |
char |
charAt(int index)
Returns the character at the specified index. |
int |
compareTo(String anotherString)
Compares this String to another specified String. |
String |
concat(String str)
Concatenates the specified string to the end of this String and returns a new String object representing the concatenation. |
static String |
copyValueOf(char[] data)
Returns a String that is equivalent to the specified character array. |
static String |
copyValueOf(char[] data,
int offset,
int count)
Returns a String that is equivalent to the specified character array. |
boolean |
endsWith(String suffix)
Determines whether the String ends with some suffix. |
boolean |
equals(Object anObject)
Compares this String to the specified object. |
boolean |
equalsIgnoreCase(String anotherString)
Compares this String to another object. |
void |
getBytes(int srcBegin,
int srcEnd,
byte[] dst,
int dstBegin)
Copies characters from this String into the specified byte array. |
void |
getChars(int srcBegin,
int srcEnd,
char[] dst,
int dstBegin)
Copies characters from this String into the specified character array. |
int |
hashCode()
Returns a hashcode for this String. |
int |
indexOf(int ch)
Returns the index within this String of the first occurrence of the specified 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 fromIndex. |
int |
indexOf(String str)
Returns the index within this String of the first occurrence of the specified substring. |
int |
indexOf(String str,
int fromIndex)
Returns the index within this String of the first occurrence of the specified substring. |
String |
intern()
Returns a String that is equal to this String but which is guaranteed to be from the unique String pool. |
int |
lastIndexOf(int ch)
Returns the index within this String of the last occurrence of the specified character. |
int |
lastIndexOf(int ch,
int fromIndex)
Returns the index within this String of the last occurrence of the specified character. |
int |
lastIndexOf(String str)
Returns the index within this String of the rightmost occurrence of the specified substring. |
int |
lastIndexOf(String str,
int fromIndex)
Returns the index within this String of the last occurrence of the specified substring. |
int |
length()
Returns the length of the String. |
boolean |
regionMatches(boolean ignoreCase,
int toffset,
String other,
int ooffset,
int len)
Determines whether a region of this String matches the specified region of the specified String. |
boolean |
regionMatches(int toffset,
String other,
int ooffset,
int len)
Determines whether a region of this String matches the specified region of the specified String. |
String |
replace(char oldChar,
char newChar)
Converts this String by replacing all occurences of oldChar with newChar. |
boolean |
startsWith(String prefix)
Determines whether this String starts with some prefix. |
boolean |
startsWith(String prefix,
int toffset)
Determines whether this String starts with some prefix. |
String |
substring(int beginIndex)
Returns the substring of this String. |
String |
substring(int beginIndex,
int endIndex)
Returns the substring of a String. |
char[] |
toCharArray()
Converts this String to a character array. |
String |
toLowerCase()
Converts all of the characters in this String to lower case. |
String |
toString()
Converts the object (in this case already a String) to a String. |
String |
toUpperCase()
Converts all of the characters in this String to upper case. |
String |
trim()
Trims leading and trailing whitespace from this String. |
static String |
valueOf(boolean b)
Returns a String object that represents the state of the specified boolean. |
static String |
valueOf(char c)
Returns a String object that contains a single character |
static String |
valueOf(char[] data)
Returns a String that is equivalent to the specified character array. |
static String |
valueOf(char[] data,
int offset,
int count)
Returns a String that is equivalent to the specified character array. |
static String |
valueOf(double d)
Returns a String object that represents the value of the specified double. |
static String |
valueOf(float f)
Returns a String object that represents the value of the specified float. |
static String |
valueOf(int i)
Returns a String object that represents the value of the specified integer. |
static String |
valueOf(long l)
Returns a String object that represents the value of the specified long. |
static String |
valueOf(Object obj)
Returns a String that represents the String value of the object. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public String()
public String(String value)
value
- the initial value of the Stringpublic String(char[] value)
value
- the initial value of the Stringpublic String(char[] value, int offset, int count)
value
- the initial value of the String, an array of charactersoffset
- the offset into the value of the Stringcount
- the length of the value of the String
StringIndexOutOfBoundsException
- If the offset and count arguments are invalid.public String(byte[] ascii, int hibyte, int offset, int count)
ascii
- the bytes that will be converted to charactershibyte
- the high byte of each Unicode characteroffset
- the offset into the ascii arraycount
- the length of the String
StringIndexOutOfBoundsException
- If the offset and count arguments are invalid.public String(byte[] ascii, int hibyte)
ascii
- the byte that will be converted to charactershibyte
- the top 8 bits of each 16 bit Unicode characterpublic String(StringBuffer buffer)
buffer
- the stringbuffer to be convertedMethod Detail |
public int length()
public char charAt(int index)
index
- the index of the desired character
StringIndexOutOfBoundsException
- If the index is not
in the range 0 to length()-1.public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
srcBegin
- index of the first character in the stringsrcEnd
- end of the characters that are copieddst
- the destination arraydstBegin
- the start offset in the destination arraypublic void getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin)
srcBegin
- index of the first character in the StringsrcEnd
- end of the characters that are copieddst
- the destination arraydstBegin
- the start offset in the destination arraypublic boolean equals(Object anObject)
equals
in class Object
anObject
- the object to compare this String against
Hashtable
public boolean equalsIgnoreCase(String anotherString)
anotherString
- the String to compare this String against
public int compareTo(String anotherString)
anotherString
- the String to be comparedpublic boolean regionMatches(int toffset, String other, int ooffset, int len)
toffset
- where to start looking in this Stringother
- the other Stringooffset
- where to start looking in the other Stringlen
- the number of characters to compare
public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)
ignoreCase
- if true, case is ignoredtoffset
- where to start looking in this Stringother
- the other Stringooffset
- where to start looking in the other Stringlen
- the number of characters to compare
public boolean startsWith(String prefix, int toffset)
prefix
- the prefixtoffset
- where to begin looking in the the String
public boolean startsWith(String prefix)
prefix
- the prefix
public boolean endsWith(String suffix)
suffix
- the suffix
public int hashCode()
hashCode
in class Object
Hashtable
public int indexOf(int ch)
ch
- the character to search forpublic int indexOf(int ch, int fromIndex)
ch
- the character to search forfromIndex
- the index to start the search frompublic int lastIndexOf(int ch)
ch
- the character to search forpublic int lastIndexOf(int ch, int fromIndex)
ch
- the character to search forfromIndex
- the index to start the search frompublic int indexOf(String str)
str
- the substring to search forpublic int indexOf(String str, int fromIndex)
str
- the substring to search forfromIndex
- the index to start the search frompublic int lastIndexOf(String str)
str
- the substring to search forpublic int lastIndexOf(String str, int fromIndex)
str
- the substring to search forfromIndex
- the index to start the search frompublic String substring(int beginIndex)
beginIndex
- the beginning index, inclusivepublic String substring(int beginIndex, int endIndex)
beginIndex
- the beginning index, inclusiveendIndex
- the ending index, exclusive
StringIndexOutOfBoundsException
- If the beginIndex or the endIndex is out
of range.public String concat(String str)
str
- the String which is concatenated to the end of this String
public String replace(char oldChar, char newChar)
oldChar
- the old characternewChar
- the new characterpublic String toLowerCase()
Character.toLowerCase(char)
,
toUpperCase()
public String toUpperCase()
Character.toUpperCase(char)
,
toLowerCase()
public String trim()
public String toString()
toString
in class Object
public char[] toCharArray()
public static String valueOf(Object obj)
obj
- the object to be convertedpublic static String valueOf(char[] data)
data
- the character arraypublic static String valueOf(char[] data, int offset, int count)
data
- the character arrayoffset
- the offset into the value of the Stringcount
- the length of the value of the Stringpublic static String copyValueOf(char[] data, int offset, int count)
data
- the character arrayoffset
- the offset into the value of the Stringcount
- the length of the value of the Stringpublic static String copyValueOf(char[] data)
data
- the character arraypublic static String valueOf(boolean b)
b
- the booleanpublic static String valueOf(char c)
c
- the character
public static String valueOf(int i)
i
- the integerpublic static String valueOf(long l)
l
- the longpublic static String valueOf(float f)
f
- the floatpublic static String valueOf(double d)
d
- the doublepublic String intern()
s1.intern() == s2.intern() <=> s1.equals(s2).
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |