Java implementation of the string split method
Codeaft.java
class Codeaft
{
    public static void main(String args[])
    {
        String s="Welcome to Codeaft!";
        System.out.println("———————————————————————————————————————————");
        System.out.println("Program to split the given string");
        System.out.println("———————————————————————————————————————————");
        String sarr[]=s.split(" ");
        System.out.println(sarr[0]+"\n"+sarr[1]+"\n"+sarr[2]);
        System.out.println("———————————————————————————————————————————");
    }
}
Output
codeaft@codeaft:~$ javac Codeaft.java
codeaft@codeaft:~$ java Codeaft ——————————————————————————————————————————— Program to split the given string ——————————————————————————————————————————— Welcome to Codeaft! ——————————————————————————————————————————— codeaft@codeaft:~$
Example 2
Codeaft.java
class Codeaft
{
    public static void main(String args[])
    {
        String s="Welcome to Codeaft!";
        System.out.println("———————————————————————————————————————————");
        System.out.println("Program to split the given string");
        System.out.println("———————————————————————————————————————————");
        String sarr[]=s.split("to");
        for(String str:sarr)
        {
            System.out.println(str);
        }
        System.out.println("———————————————————————————————————————————");
    }
}
Output
codeaft@codeaft:~$ javac Codeaft.java
codeaft@codeaft:~$ java Codeaft ——————————————————————————————————————————— Program to split the given string ——————————————————————————————————————————— Welcome Codeaft! ——————————————————————————————————————————— codeaft@codeaft:~$
Comments and Reactions