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 7885453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:04:30+00:00 2026-06-03T05:04:30+00:00

Being a Java Newbie, I am struggling with String.split . Trying to tokenism the

  • 0

Being a Java Newbie, I am struggling with String.split. Trying to tokenism the following string

"(3,3,{S,W,P},{P,W,P},{P,P,P}),(1,2,{S,E}),(2,1,{{S},{E}})"

with the regex pattern "\\{|\\(|\\}|\\)|\\s|," using String.split.

Unfortunately, it also returns empty Strings where ever match occurs which I want to suppress similar to what StringSplitOptions.RemoveEmptyEntries does in C#.

On the contrary using StringTokenizer works quite well, but being deprecated I am trying to avoid it. To make my question clear I am trying an equivalent behavior with String.split as I would get using the following Tokenizer

new StringTokenizer(input2, "{},() \t")

Please suggest, how should I proceed.

  • 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-03T05:04:31+00:00Added an answer on June 3, 2026 at 5:04 am

    First, you can eliminate most of those backslashes by using a character class instead of alternation. Then, as Christopher said, you can add a + to mimic StringTokenizer’s behavior of matching one or more delimiter characters:

    "[{},()\\s]+"
    

    Unfortunately, there’s no way to prevent that first, empty token when the string starts with a delimiter. Trailing empty tokens are automatically dropped, but you have to filter out the leading one yourself.

    Of course, you’re free to use StringTokenizer if you want, or a third-party tool like Guava’s Splitter.

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

Sidebar

Related Questions

As someone who came from Java background and being a newbie to Ruby, I
Java Newbie question : I need to capture the text being written to a
Being a Java developer in an agile development cycle, I have learnt that it
I always hear that Java being open-source is a big benefit, but I fail
SSL configuration in Java/Tomcat being what it is, I configured a tomcat6 instance to
Question Is it possible to get the version of the Java Plugin being used
Being vaguely familiar with the Java world I was googling for a static analysis
I'm currently building a Java app that could end up being run on many
I have a Java Swing application that is being used as a cluster application.
I have a Java application which requires certain software (one of them being Perl)

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.