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

  • SEARCH
  • Home
  • 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 8933959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:40:21+00:00 2026-06-15T09:40:21+00:00

I am trying to break string on delim //. My string also contains /

  • 0

I am trying to break string on delim “//”. My string also contains “/” and StringTokenizer giving strange result, it also break string on “/”.

  String  mStr = "abcd//aaa//32434//3/34343";
        StringTokenizer tok = new StringTokenizer(mStr, "//");
        while(tok.hasMoreTokens()){
            System.out.println(tok.nextToken());
        }

the result is

abcd
aaa
32434
3
34343

And the expected result is

    abcd
    aaa
    32434
    3/34343

Why this is happening and what is the solution of it? I do not want to replace “/” with other characters.

  • 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-15T09:40:23+00:00Added an answer on June 15, 2026 at 9:40 am

    StringTokenizer takes both the tokens as separate, and tokenizes on both of them. So, it is tokenizing on both // and /, and hence the result.


    I would rather prefer String#split over StringTokenizer. It’s easier to use, and has more options. It can take Regex as parameter, and returns an array of tokens which you can use later on: –

    String  mStr = "abcd//aaa//32434//3/34343";
    
    String[] arr = mStr.split("//");
    System.out.println(Arrays.toString(arr));
    

    Output : –

    [abcd, aaa, 32434, 3/34343]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to find a way to break a string at the second last
I am trying to break a large string of text into several smaller strings
I am trying to use a simple split to break up the following string:
I am trying to break a string at every occurrence of 'E'. But in
I am trying to break up this string by first splitting it into sections
I'm Trying to get a php string to break down into individual words, search
I'm trying to break up this string, AFRIKAANS = af ALBANIAN = sq AMHARIC
I've never done this before, but basically I'm trying to break a large string
I am actually trying to put a line break in a string in an
I have the following string [01][23.81][New] I am trying to break up the string

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.