How to use StringTokenizer in Java
Package : java.util.StringTokenizer
Extends : java.lang.Object class
Implements : Enumeration
Syntax :
public StringTokenizer(String str) or public StringTokenizer(String str, String delim) or public StringTokenizer(String str, String delim, boolean returnDelims)
Tutorial :
package com.javaindetail.tokenizertutorial;
import java.util.StringTokenizer;
public class SplitUsingTokenizer {
public static void main(String[] args) {
String str = "welcome-to-javaindetail.com";
StringTokenizer strToken = new StringTokenizer(str, "-");
// stringtokenizer in java
System.out.println("Splitting using StringTokenizer with - as delimiter");
while (strToken.hasMoreTokens()) {
System.out.println(strToken.nextElement());
}
}
}
Output :
welcome
to
javaindetail.com
Enjoy Reading This Article?
Here are some more articles you might like to read next: