StringTokenizer class might be very usefull especially when you read a text data from a socket. Here is an example to show how we can use this class.
package tokenizer;
import java.util.StringTokenizer;
/**
*
* @author nurhak.kaya
*/
public class Tokenizer {
public static void main(String[] args) {
String text1 = "This is a sample text!";
String text2 = "30.01.2012";
StringTokenizer st1 = new StringTokenizer(text1);
StringTokenizer st2 = new StringTokenizer(text2, ".");
while (st1.hasMoreElements()) {
String string1 = (String) st1.nextElement();
System.out.println(" --> " + string1);
}
System.out.println("/////////////////////");
while (st2.hasMoreElements()) {
String string2 = (String) st2.nextElement();
System.out.println(" --> " + string2);
}
}
}
package tokenizer;
import java.util.StringTokenizer;
/**
*
* @author nurhak.kaya
*/
public class Tokenizer {
public static void main(String[] args) {
String text1 = "This is a sample text!";
String text2 = "30.01.2012";
StringTokenizer st1 = new StringTokenizer(text1);
StringTokenizer st2 = new StringTokenizer(text2, ".");
while (st1.hasMoreElements()) {
String string1 = (String) st1.nextElement();
System.out.println(" --> " + string1);
}
System.out.println("/////////////////////");
while (st2.hasMoreElements()) {
String string2 = (String) st2.nextElement();
System.out.println(" --> " + string2);
}
}
}
Güzel bir paylaşım elinize sağlık...
ReplyDelete