22)Use the classes StringTokenizer, StringReader and StringWriter to write a program to find the capabilities of these classes.

PHOTO EMBED

Mon Jul 08 2024 06:17:59 GMT+0000 (Coordinated Universal Time)

Saved by @varuntej #java

import java.util.StringTokenizer;
import java.io.StringReader;
import java.io.StringWriter;

public class StringExample {
    public static void main(String[] args) {
        try {
            StringTokenizer st = new StringTokenizer("My name is Raj");

            while (st.hasMoreTokens()) {
                System.out.println(st.nextToken());
            }

            String s = "Hello World";

            StringReader reader = new StringReader(s);
            int k = 0;

            while ((k = reader.read()) != -1) {
                System.out.print((char) k + ", ");
            }

            System.out.println("\nIn Data is the StringWriter: " + s);

            StringWriter output = new StringWriter();
            output.write(s);

            System.out.println("In Data is the StringWriter: " + output.toString());

            output.close();
        } catch (Exception e) {
            System.out.println("Exception: " + e.getMessage());
        }
    }
}
content_copyCOPY