Mega Code Archive

 
Categories / Java / Data Type
 

Split on word boundaries

import java.util.Arrays; public class Main {   public static void main(String[] argv) throws Exception {     String testStr = "One, Two, and Three.";     System.out.println("Original string: " + testStr);     String[] result = testStr.split("\\W+");     System.out.print("Split at word boundaries: ");     System.out.println(Arrays.toString(result));   } } /* Original string: One, Two, and Three. Split at word boundaries: [One, Two, and, Three] */