Class java.lang.String

The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class.

Strings are constant; their values cannot be changed after they are created. String buffers support mutable strings.

The class String includes methods for examining individual characters of the sequence, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase or to lowercase.

The Java language provides special support for the string concatentation operator ( + ), and for conversion of other objects to strings. String concatenation is implemented through the StringBuffer class and its append method. String conversions are implemented through the method toString, defined by Object and inherited by all classes in Java.

charAt(int)

Returns the character at the specified index.

compareTo(String)

Compares two strings lexicographically.

concat(String)

Concatenates the specified string to the end of this string.

endsWith(String)

Tests if this string ends with the specified suffix.

equals(Object)

Compares this string to the specified object.

equalsIgnoreCase(String)

Compares this String to another object.

indexOf(String)

Returns the index within this string of the first occurrence of the specified substring.

lastIndexOf(String)

Returns the index within this string of the rightmost occurrence of the specified substring.

length()

Returns the length of this string.

regionMatches(int, String, int, int)

Tests if two string regions are equal.

replace(char, char)

Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.


startsWith(String)

Tests if this string starts with the specified prefix.

substring(int startchar, int endchar)

Returns a new string that is a substring of this string starting at character startchar and ending at character endchar-1. The returned string has the length endchar startchar.

toLowerCase()

Converts this String to lowercase.

toUpperCase()

Converts this string to uppercase.

trim()

Removes white space from both ends of this string.

valueOf(double)

Returns the string representation of the double argument.

valueOf(float)

Returns the string representation of the float argument.

valueOf(int)

Returns the string representation of the int argument

 

 

StringBuffer

 

A StringBuffer object is similar to a String, but it can be changed. The following methods are available for StringBuffer.

 

append(String str)

Appends the string to this string buffer.

 

deleteCharAt(int index)

Removes the character at the specified position in this StringBuffer (shortening the StringBuffer by one character).

 

delete(int start, int end)

Removes the characters in a substring of this StringBuffer

 

insert(int offset, char c)

Inserts the string representation of the char argument into this string buffer.

 

insert(int offset, String str)

Inserts the string into this string buffer.

 

reverse()

The reverse of the sequence replaces the character sequence contained in this string buffer.