Preview:
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());
        }
    }
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter