Sunday, 7 December 2014

WAP splitting a string

//Strsplit.java
class  Strsplit
{
public static void main(String[] args)
{
//take a string which is to be broken
String str="Hello, this is a book on java";

//declare a string type array s to store pieces
String s[ ];
//split the string where where a space is found in str
s=str.split(" ");

//displaying the pieces from s
for(int i=0; i<s.length; i++)
System.out.println(s[i]);
}
}

No comments:

Post a Comment