Question 05 of 05

String Methods

Write a Java program to demonstrate various String methods.

C++
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