/** * SplitDemo.java * A quick demo of a way to use the String.split function for HW4. * * @author Samuel A. Rebelsky * @version 0.1 of 14 September 2014 */ import java.io.PrintWriter; import java.util.Arrays; /** * Watch what happens when we split strings. */ public class SplitDemo { /** * One demo. Split a string using a pattern, printing the * results with a pen. */ public static void demo(PrintWriter pen, String str, String pattern) { pen.println(" Using \"" + pattern + "\""); pen.print(" "); pen.println(Arrays.toString(str.split(pattern))); } // demo(PrintWriter, String, String) /** * One set of demos. Split a string in multiple ways, printing * results using the pen. */ public static void demo(PrintWriter pen, String str) { pen.println("Splitting \"" + str + "\""); demo(pen, str, " "); demo(pen, str, " *"); demo(pen, str, " +"); pen.println(); } // demo(PrintWriter, String) public static void main(String[] args) throws Exception { PrintWriter pen = new PrintWriter(System.out, true); demo(pen, "3 + 4 + 5"); demo(pen, "3 + 4 + 5"); pen.close(); } // main(String[]) } // SplitDemo