0% found this document useful (0 votes)
26 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)
26 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy