How do I split a string? - JAVA Interview Questions

How do I split a string?


String class introduce a String.split(String regex) method that simplify this process.

Below is a code sample how to do it.



public class StringSplit
{
public static void main(String[] args)
{
String data = "1,Diego Maradona,Footballer,Argentina";
String[] items = data.split(",");
for (String item : items)
{
System.out.println("item = " + item);
}
}
}



Click Here to See Answer .....
Did you like this article ?
Subscribe to my RSS feed and get more JAVA Question, and Guideline, Plus a lot more great advice to help your Software Career.

1 comments:

trustno1 said...

java applet example codes
Fade an Image

Related JAVA Questions Posts