Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
21 views

Java String Reference

The document discusses the built-in methods available for the Java String class. It lists over 30 common string methods like charAt(), compareTo(), concat(), contains(), indexOf(), length(), replace(), split(), substring(), toLowerCase(), trim(), and valueOf(). Each method is described briefly, noting what it does and its return type.

Uploaded by

Manjula
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Java String Reference

The document discusses the built-in methods available for the Java String class. It lists over 30 common string methods like charAt(), compareTo(), concat(), contains(), indexOf(), length(), replace(), split(), substring(), toLowerCase(), trim(), and valueOf(). Each method is described briefly, noting what it does and its return type.

Uploaded by

Manjula
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

6/5/2020 Java String Reference

  HTML CSS MORE   


w3schools.com

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 Unicode in the specified int


text range of this 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

https://www.w3schools.com/java/java_ref_string.asp 1/6
6/5/2020 Java String Reference

contentEquals() Checks whether a string contains the boolean


  HTML CSS MORE   
exact same sequence of characters of
the specified CharSequence or
StringBuffer

copyValueOf() Returns a String that represents the String


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() Encodes this String into a sequence of byte[]


bytes using the named charset, storing
the result into a new byte array

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 index within this string of String


the first occurrence of the specified
character, starting the search at the
specified index

isEmpty() Checks whether a string is empty or not boolean

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

https://www.w3schools.com/java/java_ref_string.asp 2/6
6/5/2020 Java String Reference

offsetByCodePoints() Returns the index within this String that int


  HTML CSS MORE   
is offset from the given index by
codePointOffset code points

regionMatches() Tests if two string regions are equal boolean

replace() Searches a string for a specified value, String


and returns a new string where the
specified values are replaced

replaceFirst() Replaces the first occurrence of a String


substring that matches the given
regular expression with the given
replacement

replaceAll() Replaces each substring of this string String


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() Extracts the characters from a string, String


beginning at a specified start position,
and through the specified number of
character

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 primitive value of a String String


object

❮ Previous Next ❯

https://www.w3schools.com/java/java_ref_string.asp 3/6

You might also like