This is one of the important methods of String. split(String regex) :- Splits this string around matches of the given regular expression.
Here is the source code of the Java Program to Split into Pieces Wherever a Space is Found. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
public class Split_Demo
public static void main(String... a)
String s1 = "HelloJava from JavaGuy";
String s2 = s1.split(" ");
String part1 = s2;
String part2 = s2;
String part3 = s2;
System.out.println("The string after spliting is "+part1+ " and "+part2);
$ javac Split_Demo.java $ java Split_Demo The string after spliting is Hello and Java
Sanfoundry Global Education & Learning Series – 1000 Java Programs.