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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:14:57+00:00 2026-06-14T17:14:57+00:00

I need to split an expression like a+b-c*d/e and get a , b ,

  • 0

I need to split an expression like

a+b-c*d/e 

and get a, b, c, d, e seperately(as array of strings) as well as =,-,*,d,/(also an array of operators) separately. I have tried like:

String myString;

String myString={"a+b-c*d/e");

String[] result=new String();

String[] separator=new String[]{"+","-","/","*"};

result=myString.split(separator);

But, it shows an error. How to solve it?

  • 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-14T17:14:58+00:00Added an answer on June 14, 2026 at 5:14 pm

    1st problem: –

    Multiple declaration of String myString;

    2nd problem: –

    String initialized incorrectly. Double quotes missing at the ends. Remove bracket and brace from the ends.

    String myString = "a+b-c*d/e";
    

    3rd problem: –

    String array initialized with an String object, rather than an array object.

    String[] result=new String();  // Should be `new String[size]`
    

    In fact, you don’t need to initialize your array before hand.

    4th problem: –

    String.split takes a Regular Expression as argument, you have passed an array. Will not work.

    Use: –

    String[] result = myString.split("[-+*/]");
    

    to split on all the operators.


    And regarding your this statement: –

    as well as =, -, *, d, / (also an array of operators) separately.

    I don’t understand what you want here. Your sample string does not contains =. And d is not an operator. Please see if you want to edit it.

    UPDATE : –

    If you mean to keep the operators as well in your array, you can use this regex: –

    String myString= "a+b-c*d/e";
    String[] result = myString.split("(?<=[-+*/])|(?=[-+*/])");
    System.out.println(Arrays.toString(result));
    
    /*** Just to see, what the two parts in the above regex print separately ***/
    System.out.println(Arrays.toString(myString.split("(?<=[-+*/])")));
    System.out.println(Arrays.toString(myString.split("(?=[-+*/])")));
    

    OUTPUT : –

    [a, +, b, -, c, *, d, /, e]
    [a+, b-, c*, d/, e]
    [a, +b, -c, *d, /e]
    

    (?<=...) means look-behind assertion, and (?=...) means look-ahead assertion.

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

Sidebar

Related Questions

I need a regular expression that would split strings like itemXY where X and
I need to split my string input into an array at the commas. Is
I need to split long string into a array with following constrains: The input
I have a string like: {A}{B}={C}{D}<{E}{F}<= What I want to do is split that
I need to split an expression (String) in pieces and call a recursive function
I have a string that I need to split on multiple characters without the
I have a string in Java that I need to split using <$ and
I need to split a string like the one below, based on space as
Basically I have these connection strings that I need to split up, heres an
I have an expression like /a/b/c.d/f. I need all the characters in between /

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.