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

Java String CheatSheet

This document is a cheat sheet for Java String methods, providing a list of common methods with their descriptions and examples. It includes methods like length(), charAt(), substring(), equals(), and more, detailing their functionalities. The cheat sheet is a quick reference for developers to utilize string operations in Java programming.

Uploaded by

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

Java String CheatSheet

This document is a cheat sheet for Java String methods, providing a list of common methods with their descriptions and examples. It includes methods like length(), charAt(), substring(), equals(), and more, detailing their functionalities. The cheat sheet is a quick reference for developers to utilize string operations in Java programming.

Uploaded by

patilvandesh301
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Java String Mastery Cheat Sheet

1. Java String Methods


length()
Returns the length of the string.
Example: str.length();

charAt(int index)
Returns the character at the specified index.
Example: str.charAt(2);

substring(int start, int end)


Returns a substring.
Example: str.substring(1, 4);

equals(String s)
Checks string equality.
Example: str.equals("Hello");

equalsIgnoreCase(String s)
Checks equality ignoring case.
Example: str.equalsIgnoreCase("hello");

compareTo(String s)
Compares two strings lexicographically.
Example: str.compareTo("apple");

indexOf(String s)
Returns index of first occurrence.
Example: str.indexOf("lo");

lastIndexOf(String s)
Returns last index of occurrence.
Example: str.lastIndexOf("l");

contains(CharSequence s)
Checks if string contains sequence.
Example: str.contains("ell");

toUpperCase()
Converts to uppercase.
Example: str.toUpperCase();

toLowerCase()
Converts to lowercase.
Example: str.toLowerCase();

trim()
Removes leading/trailing spaces.
Example: str.trim();

replace(char old, char new)


Replaces characters.
Example: str.replace("a", "o");

split(String regex)
Splits string around matches.
Example: str.split(" ");

toCharArray()
Converts string to char array.
Example: char[] chars = str.toCharArray();

isEmpty()
Checks if string is empty.
Example: str.isEmpty();

isBlank()
Checks if string is blank (Java 11+).
Example: str.isBlank();

You might also like