OnJava8-Examples/strings/SplitDemo.java
2015-05-29 14:18:51 -07:00

21 lines
583 B
Java

//: strings/SplitDemo.java
// ©2015 MindView LLC: see Copyright.txt
import java.util.regex.*;
import java.util.*;
import static net.mindview.util.Print.*;
public class SplitDemo {
public static void main(String[] args) {
String input =
"This!!unusual use!!of exclamation!!points";
print(Arrays.toString(
Pattern.compile("!!").split(input)));
// Only do the first three:
print(Arrays.toString(
Pattern.compile("!!").split(input, 3)));
}
} /* Output:
[This, unusual use, of exclamation, points]
[This, unusual use, of exclamation!!points]
*///:~