0 day streak
java / beginner
Snippet

Common String Methods

Strings in Java are objects that come with built-in methods to perform operations like checking length, changing case, or searching for text.

snippet.java
java
1
2
3
4
String greeting = "Hello World";
int size = greeting.length();
String upper = greeting.toUpperCase();
boolean contains = greeting.contains("Hello");
Breakdown
1
int size = greeting.length();
Returns the number of characters in the string.
2
String upper = greeting.toUpperCase();
Creates a new string where all characters are converted to uppercase.
3
greeting.contains("Hello");
Checks if the string contains the specified sequence of characters.