This is a Java Program to Split into Pieces Wherever a Space is Found.
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[0];
String part2 = s2[1];
String part3 = s2[2];
System.out.println("The string after spliting is "+part1+ " and "+part2);
}
}
Output:
$ javac Split_Demo.java $ java Split_Demo The string after spliting is Hello and Java
Sanfoundry Global Education & Learning Series – 1000 Java Programs.
advertisement
Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.
Related Posts:
- Practice BCA MCQs
- Apply for Computer Science Internship
- Practice Information Technology MCQs
- Practice Programming MCQs
- Check Programming Books