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

Java String Methods

The document provides an overview of various Java String methods categorized into case conversion, searching, modification, comparison, testing, and formatting. Each category includes examples demonstrating the usage of the methods. This serves as a reference for developers to understand and utilize Java String methods effectively.
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)
2 views2 pages

Java String Methods

The document provides an overview of various Java String methods categorized into case conversion, searching, modification, comparison, testing, and formatting. Each category includes examples demonstrating the usage of the methods. This serves as a reference for developers to understand and utilize Java String methods effectively.
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 Methods with Categories and Examples

Case Conversion Methods

toUpperCase(): "hello".toUpperCase() -> "HELLO"

toLowerCase(): "HELLO".toLowerCase() -> "hello"

trim(): " hello ".trim() -> "hello"

Searching Methods

indexOf(): "hello".indexOf('e') -> 1

lastIndexOf(): "hellohello".lastIndexOf('e') -> 6

contains(): "hello".contains("ell") -> true

startsWith(): "hello".startsWith("he") -> true

endsWith(): "hello".endsWith("lo") -> true

Modification Methods

replace(): "hello".replace('l', 'p') -> "heppo"

substring(): "hello".substring(1, 4) -> "ell"

concat(): "hello".concat(" world") -> "hello world"

repeat(): "ha".repeat(3) -> "hahaha"

Comparison Methods

equals(): "hello".equals("hello") -> true

equalsIgnoreCase(): "HELLO".equalsIgnoreCase("hello") -> true

compareTo(): "abc".compareTo("abd") -> -1

compareToIgnoreCase(): "abc".compareToIgnoreCase("ABC") -> 0

Testing Methods

isEmpty(): "".isEmpty() -> true

isBlank(): " ".isBlank() -> true


matches(): "abc123".matches("[a-z]+[0-9]+") -> true

Formatting Methods

format(): String.format("Hello %s", "World") -> "Hello World"

valueOf(): String.valueOf(123) -> "123"

join(): String.join(", ", "a", "b", "c") -> "a, b, c"

You might also like