How to Use StringTokenizer with Multiple Delimiters in Java


This example is to show how to use StringTokenizer with multiple delimiters in Java.

Source Code

package com.beginner.examples;

import java.util.StringTokenizer;

public class StringTokenizerMultipleExample {
    public static void main(String a[]){
        String url = "http://127.0.0.1:8080/";
        StringTokenizer s = new StringTokenizer(url, ":/");
        while(s.hasMoreTokens()){
            System.out.println(s.nextToken());
        }
    }
}

Output:

http
127.0.0.1
8080

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments