0% found this document useful (0 votes)
21 views3 pages

Java_String_Methods_CheatSheet

This document is a cheat sheet for Java String methods, providing a list of common methods along with examples of their usage. It includes methods for string manipulation such as length, substring, equals, and various others. Additionally, it highlights newer methods introduced in Java 11, like isBlank and strip.

Uploaded by

md2004sameer01
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)
21 views3 pages

Java_String_Methods_CheatSheet

This document is a cheat sheet for Java String methods, providing a list of common methods along with examples of their usage. It includes methods for string manipulation such as length, substring, equals, and various others. Additionally, it highlights newer methods introduced in Java 11, like isBlank and strip.

Uploaded by

md2004sameer01
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/ 3

Java String Methods Cheat Sheet

length()

Example: str.length();

charAt(int index)

Example: str.charAt(0);

substring(int beginIndex)

Example: str.substring(2);

substring(int beginIndex, int endIndex)

Example: str.substring(2, 5);

equals(String another)

Example: str1.equals(str2);

equalsIgnoreCase(String another)

Example: str1.equalsIgnoreCase(str2);

isEmpty()

Example: str.isEmpty();

isBlank()

Example: str.isBlank(); // Java 11+

trim()

Example: str.trim();

toLowerCase()

Example: str.toLowerCase();

toUpperCase()

Example: str.toUpperCase();

concat(String str)

Example: str.concat("World");

indexOf(String str)

Example: str.indexOf("a");

lastIndexOf(String str)

Example: str.lastIndexOf("a");
contains(CharSequence s)

Example: str.contains("text");

startsWith(String prefix)

Example: str.startsWith("He");

endsWith(String suffix)

Example: str.endsWith("ld");

matches(String regex)

Example: str.matches("\\d+");

replace(char oldChar, char newChar)

Example: str.replace('a', 'b');

replaceAll(String regex, String replacement)

Example: str.replaceAll("a", "b");

replaceFirst(String regex, String replacement)

Example: str.replaceFirst("a", "b");

strip()

Example: str.strip(); // Java 11+

stripLeading()

Example: str.stripLeading();

stripTrailing()

Example: str.stripTrailing();

split(String regex)

Example: str.split(" ");

toCharArray()

Example: char[] arr = str.toCharArray();

valueOf(int i)

Example: String.valueOf(100);

compareTo(String another)

Example: str1.compareTo(str2);

intern()

Example: str.intern();
repeat(int count)

Example: str.repeat(3); // Java 11+

You might also like