Thursday, August 26, 2010

String.split()

Use of the String.split()
split() is used to split a given string based on a pattern.......

code :


public class UseOfSplit {
public static void main(String args[]) {
String str = "This is the sample String to split";
String pattern=" ";
String[] tmp = str.split(pattern);
for (int i = 0; i < tmp.length; i++) {
System.out.println(tmp[i] + "------");
}
}
}


output :


This------
is------
the------
sample------
String------
to------
split------

No comments:

Post a Comment