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.


Returns the character at the specified index.


Compares two strings lexicographically.


Concatenates the specified string to the end of this string.


Tests if this string ends with the specified suffix.


Compares this string to the specified object.


Compares this String to another object.


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


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


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.


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.


Converts this String to lowercase.


Converts this string to uppercase.


Removes white space from both ends of this string.


Returns the string representation of the double argument.


Returns the string representation of the float argument.


Returns the string representation of the int argument





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.



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