2/11/25, 2:50 PM Java String Reference
Tutorials Exercises Services Sign Up Log in
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
Java String Methods
❮ Previous Next ❯
All String Methods
The String class has a set of built-in methods that you can use on strings.
Method Description Return Type
charAt() Returns the character at the specified char
index (position)
codePointAt() Returns the Unicode of the character at int
the specified index
codePointBefore() Returns the Unicode of the character int
before the specified index
codePointCount() Returns the number of Unicode values int
found in a string.
compareTo() Compares two strings lexicographically int
compareToIgnoreCase() Compares two strings lexicographically, int
ignoring case differences
concat() Appends a string to the end of another String
string
contains() Checks whether a string contains a boolean
sequence of characters
contentEquals() Checks whether a string contains the boolean
exact same sequence of characters of
[Link] 1/6
2/11/25, 2:50 PM Java String Reference
the specified CharSequence or
Tutorials Exercises Services
StringBuffer Sign Up Log in
HTML CSS JAVASCRIPT
copyValueOf() SQL a PYTHON
Returns JAVA PHP
String that represents the HOWString
TO [Link] C
characters of the character array
endsWith() Checks whether a string ends with the boolean
specified character(s)
equals() Compares two strings. Returns true if boolean
the strings are equal, and false if not
equalsIgnoreCase() Compares two strings, ignoring case boolean
considerations
format() Returns a formatted string using the String
specified locale, format string, and
arguments
getBytes() Converts a string into an array of bytes byte[]
getChars() Copies characters from a string to an void
array of chars
hashCode() Returns the hash code of a string int
indexOf() Returns the position of the first found int
occurrence of specified characters in a
string
intern() Returns the canonical representation for String
the string object
isEmpty() Checks whether a string is empty or not boolean
join() Joins one or more strings with a String
specified separator
lastIndexOf() Returns the position of the last found int
occurrence of specified characters in a
string
length() Returns the length of a specified string int
matches() Searches a string for a match against a boolean
regular expression, and returns the
matches
offsetByCodePoints() Returns the index within this String that int
is offset from the given index by
[Link] 2/6
2/11/25, 2:50 PM Java String Reference
codePointOffset code points
Tutorials Exercises Services Sign Up Log in
regionMatches() Tests if two string regions are equal boolean
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
replace() Searches a string for a specified value, String
and returns a new string where the
specified values are replaced
replaceAll() Replaces each substring of this string String
that matches the given regular
expression with the given replacement
replaceFirst() Replaces the first occurrence of a String
substring that matches the given
regular expression with the given
replacement
split() Splits a string into an array of String[]
substrings
startsWith() Checks whether a string starts with boolean
specified characters
subSequence() Returns a new character sequence that CharSequence
is a subsequence of this sequence
substring() Returns a new string which is the String
substring of a specified string
toCharArray() Converts this string to a new character char[]
array
toLowerCase() Converts a string to lower case letters String
toString() Returns the value of a String object String
toUpperCase() Converts a string to upper case letters String
trim() Removes whitespace from both ends of String
a string
valueOf() Returns the string representation of the String
specified value
Related Pages
Java Strings Tutorial
[Link] 3/6
2/11/25, 2:50 PM Java String Reference
❮ Previous
Tutorials Exercises Services Sign Up Log in
Next ❯
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
Track your progress - it's free! Sign Up Log in
COLOR PICKER
[Link] 4/6
2/11/25, 2:50 PM Java String Reference
Tutorials Exercises Services Sign Up Log in
HTML
CSS
PLUS
JAVASCRIPT SQL
SPACES
PYTHON
GET CERTIFIED
JAVA PHP HOW TO [Link] C
FOR TEACHERS FOR BUSINESS CONTACT US
Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
[Link] Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial
Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
[Link] Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference
Top Examples Get Certified
HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
[Link] Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate
jQuery Examples XML Certificate
FORUM ABOUT ACADEMY
[Link] 5/6
2/11/25, 2:50 PM Java String Reference
W3Schools is optimized for learning and training. Examples might be simplified to
improve reading and learning.
Tutorials Exercises Services Sign Up
Tutorials, references, and examples are constantly reviewed to avoid errors, but we
Log in
cannot warrant full correctness
HTML
CSS of allJAVASCRIPT
content. While using
SQLW3Schools,
PYTHONyou agreeJAVA
to have read
PHPand accepted
HOW TO our [Link] C
terms of use, cookie and privacy policy.
Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by
[Link].
[Link] 6/6