String Methods
Strings are immutable. Use length, charAt, substring, indexOf, replace, toUpperCase, trim, split and equals.
Example
public class Main {
public static void main(String[] args) {
String s = " Hello Java ";
String t = s.trim();
System.out.println(t.length() + " " + t.charAt(0) + " " + t.substring(6) + " " + t.indexOf("Java"));
System.out.println(t.toUpperCase() + " " + t.replace("l", "L"));
}
}Result
10 H Java 6 HELLO JAVA HeLLo Java
Exercise
Compare text.
a.(b)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.