Example & Tutorial understanding programming in easy ways.

How to Split String in java?

Below example shows how to split or brake a string. The split() method splits the string based on the given regular expression or delimiter, and returns the tokens in the form of array. Below example shows splitting string with space, and second split is based on any kind of spaces, that includes tab, enter, line breaks, etc.

 example:

public class Splittest {

public static void main(String a[]){

String s = "This program splits a string based on space";

String[] tokens = s.split(" ");

for(String s:tokens){

System.out.println(s);}

s = "This program splits a string based on space";

tokens = s.split("\\s+");}}

Read More →
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!