classKW{publicstaticvoidmain(Stringargs[]){Strings="Welcome to Kodingwindow!";System.out.println("———————————————————————————————————————————");System.out.println("Program to split the given string");System.out.println("———————————————————————————————————————————");Stringsarr[]=s.split(" ");System.out.println(sarr[0]+"\n"+sarr[1]+"\n"+sarr[2]);System.out.println("———————————————————————————————————————————");}}
Output
kodingwindow@kw:~$ javac KW.java kodingwindow@kw:~$ java KW
———————————————————————————————————————————
Program to split the given string
———————————————————————————————————————————
Welcome
to
Kodingwindow!
———————————————————————————————————————————
kodingwindow@kw:~$
Example 2
KW.java
classKW{publicstaticvoidmain(Stringargs[]){Strings="Welcome to Kodingwindow!";System.out.println("———————————————————————————————————————————");System.out.println("Program to split the given string");System.out.println("———————————————————————————————————————————");Stringsarr[]=s.split("to");for(Stringstr:sarr){System.out.println(str);}System.out.println("———————————————————————————————————————————");}}
Output
kodingwindow@kw:~$ javac KW.java kodingwindow@kw:~$ java KW
———————————————————————————————————————————
Program to split the given string
———————————————————————————————————————————
Welcome
Kodingwindow!
———————————————————————————————————————————
kodingwindow@kw:~$
Dear User, Thank you for visitng Kodingwindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.
Dear User, We are grateful for your interest in the Kodingwindow Android app. We intend to soon make it available on the Google Play Store. Currently, Android versions 10 and up require manual apk installations. Would you like to get the app?