Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8410227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:07:22+00:00 2026-06-10T00:07:22+00:00

I am new to java progrmming and came across the StringTokenizer class. The constructor

  • 0

I am new to java progrmming and came across the StringTokenizer class. The constructor accepts the string to be split and another optional delimiter string each character of which gets treated as an individual delimiter while splitting the original string. I was wondering if there is any way to split the string passing a regex as the delimiter. for example:

String s="34.5xy32.6y45.7x36xy"
StringTokenizer t=new StringTokenizer(s,"xy");
System.out.println(t.nextToken());
System.out.println(t.nextToken());

The actual output is:

34.5
32.6

However, the desired output is:

34.5
32.6y45.7x36

Hope you guys can help. Also, please suggest some way around if it is not possible with StringTokenizer class.

Thanks in advance.

p.s. Is there any way to know which character the StringTokenizer is currently using as delimiter out of the provided set?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:07:23+00:00Added an answer on June 10, 2026 at 12:07 am

    Here you would want to use String.split(), this will give you an array with your desired output.

    It will take your input and split it around exact matches of your string you provide. StringTokenizer will split around anyone of the set that you provide it rather than a regular expression.

    So you change your code to:

    String s="34.5xy32.6y45.7x36xy";
    String[] splitString = s.split("xy");
    System.out.println(splitString [0]);
    System.out.println(splitString [1]);
    

    For more complex examples you probably want boundary checking on the array also to make you don’t go off the end of the array

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am relatively new to Java and while trying out some code came across
I came across something new which i really found hard to understand.. Here is
Last night I came across the term called Jython which was kind of new
I am new to Java programming, i created one class with name as Demo
I'm new to Java programming and am facing a (most likely) easy problem that
I'm new to Java programming. I want to write simple Java network protocol. I
hi I am new here and new in Java programming as well actually my
sry about my english :) Im new to Java programming and i have a
First, i'm new at Java-programming and my native lang is not english, but still
I have been working on Eclipse recently. I am fairly new to java programming,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.