15)Write a program to understand the full capability of String class.Implement as many methods as required. Consult API documentation to read through the methods.

PHOTO EMBED

Mon Jul 08 2024 06:12:22 GMT+0000 (Coordinated Universal Time)

Saved by @varuntej #java

public class StringExample {
    public static void main(String[] args) {
        String s = "Hello World!";
        System.out.println("Original string: " + s);
        System.out.println("Length: " + s.length());
        System.out.println("Uppercase: " + s.toUpperCase());
        System.out.println("Lowercase: " + s.toLowerCase());
        System.out.println("Substring from index 7: " + s.substring(7));
        System.out.println("Replace 'o' with 'x': " + s.replace('o', 'x'));
        System.out.println("Contains 'world': " + s.contains("world"));
        System.out.println("Starts with 'Hello': " + s.startsWith("Hello"));
        System.out.println("Index of 'o': " + s.indexOf('o'));
        System.out.println("Last index of 'o': " + s.lastIndexOf('o'));
        System.out.println("Ends with 'ld!': " + s.endsWith("ld!"));
        System.out.println("Character at index 4: " + s.charAt(4));
        System.out.println("Trimmed: " + s.trim());
    }
}
content_copyCOPY