[Go to site: main page, start]

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

Essential Java String Methods Guide

The document provides a comprehensive overview of various Java String functions, detailing their return types, arguments, and descriptions. Key methods include length(), charAt(), substring(), indexOf(), and various comparison functions like equals() and compareTo(). It serves as a reference for developers to understand and utilize string manipulation capabilities in Java.

Uploaded by

www.sarvjeet1984
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)
4 views2 pages

Essential Java String Methods Guide

The document provides a comprehensive overview of various Java String functions, detailing their return types, arguments, and descriptions. Key methods include length(), charAt(), substring(), indexOf(), and various comparison functions like equals() and compareTo(). It serves as a reference for developers to understand and utilize string manipulation capabilities in Java.

Uploaded by

www.sarvjeet1984
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

Java String Functions

Method Return Type Arguments Description

length() int None Returns the length


of the string.

charAt(int index) char index (int) Returns the


character at the
given index.

substring(int String beginIndex (int) Returns substring


beginIndex) from given index to
end.

substring(int String beginIndex (int), Returns substring


beginIndex, int endIndex (int) from beginIndex to
endIndex) endIndex-1.

indexOf(char ch) int ch (char) Returns the index of


the first occurrence
of the character.

indexOf(String str) int str (String) Returns the index of


the first occurrence
of the substring.

lastIndexOf(char ch) int ch (char) Returns the last


occurrence of the
character.

toLowerCase() String None Converts the string


to lowercase.

toUpperCase() String None Converts the string


to uppercase.

trim() String None Removes leading


and trailing spaces.

replace(char String oldChar (char), Replaces


oldChar, char newChar (char) occurrences of a
newChar) character.

replace(String String oldStr (String), Replaces


oldStr, String newStr (String) occurrences of a
newStr) substring.

equals(String boolean anotherString Compares two


anotherString) (String) strings (case-
sensitive).

equalsIgnoreCase(St boolean anotherString Compares two


ring anotherString) (String) strings (case-
insensitive).

startsWith(String boolean prefix (String) Checks if the string


prefix) starts with the given
prefix.

endsWith(String boolean suffix (String) Checks if the string


suffix) ends with the given
suffix.

contains(CharSeque boolean sequence Checks if the string


nce sequence) (CharSequence) contains the given
sequence.

split(String regex) String[] regex (String) Splits the string


based on a regular
expression.

concat(String str) String str (String) Concatenates (joins)


two strings.

compareTo(String int anotherString Compares two


anotherString) (String) strings
lexicographically.

compareToIgnoreCa int anotherString Compares two


se(String (String) strings
anotherString) lexicographically
(case-insensitive).

You might also like