Cycle 03
Lab Cycle 3 — Advanced Java
String Methods
Problem Statement
Write a Java program to demonstrate various String methods.
public class StringDemo {
public static void main(String[] args) {
String str = "Hello World";
System.out.println("Length: " + str.length());
System.out.println("Uppercase: " + str.toUpperCase());
System.out.println("Substring: " + str.substring(0, 5));
System.out.println("Replace: " + str.replace("World", "Java"));
String[] words = str.split(" ");
for (String w : words) System.out.println(w);
}
}
Question 5 of 5