Split a String into an Array in Java

Do you need to split a string into multiple values? Prior to Java 1.4, you would probably have used the StringTokenizer class to accomplish this.

In Java 1.4, Sun added a split() method to the String class. Using this method, you can very easily split a String into multiple values. The split() method takes a regular expression as a parameter which is used to split the String.

Below is an example of splitting a String:

//Data String
String data = "value 1,value 2,value 3";

//Split data into an array
String[] values = data.split(",");


Flinty said...

Thanks. Helped me out a lot.

Anonymous said...

thanks, this is the method i looked for.

Anonymous said...

thanks a lot.. i was looking for this

jeeva muthu said...


Post a Comment