0% found this document useful (0 votes)
20 views2 pages

Java String Methods Overview

Uploaded by

netanelgo99
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

Java String Methods Overview

Uploaded by

netanelgo99
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

char charAt(int index)

Returns the char value at the specified index.

int compareTo(String anotherString)


Compares two strings lexicographically.

boolean contains(CharSequence s)
Returns true if and only if this string contains the specified
sequence of char values.

static String copyValueOf(char[] data)


Returns a String that represents the character sequence in the
array specified.

boolean endsWith(String suffix)


Tests if this string ends with the specified suffix.

boolean equals(Object anObject)


Compares this string to the specified object.

int indexOf(int ch)


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

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, starting at the specified index.

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, searching backward starting at the specified
index.

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, searching backward starting at the specified
index.

int length()
Returns the length of this string.

String replace(char oldChar, char newChar)


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

String replace(CharSequence target, CharSequence replacement)


Replaces each substring of this string that matches the literal
target sequence with the specified literal replacement sequence.

boolean startsWith(String prefix)


Tests if this string starts with the specified prefix.

String substring(int beginIndex)


Returns a new string that is a substring of this string.

String substring(int beginIndex, int endIndex)


Returns a new string that is a substring of this string.

char[] toCharArray()
Converts this string to a new character array.

String toLowerCase()
Converts all of the characters in this String to lower case using
the rules of the default locale.

String toUpperCase()
Converts all of the characters in this String to upper case using
the rules of the default locale.

String trim()
Returns a copy of the string, with leading and trailing
whitespace omitted.

static String valueOf(boolean b)


Returns the string representation of the boolean argument.

static String valueOf(char c)


Returns the string representation of the char argument.

static String valueOf(double d)


Returns the string representation of the double argument.

static String valueOf(int i)


Returns the string representation of the int argument.

You might also like