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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:17:17+00:00 2026-06-15T20:17:17+00:00

Okay, Now I am able to parse space which was my previous problem. Now

  • 0

Okay, Now I am able to parse space which was my previous problem. Now my parser is almost ready but has a defect which I am unable to figure out.

I am able to retrieve Data after segments(see code) and data in between pipes.
What I am not able to get to is a level up and retrieve data which is contained between pipes and seperated by ^.

Eg.

Input String is A|1|2|3^4|
Expected Output
element1        A
element2        1
element3        2
element4.1      3
element4.2      4

However, My current output is coming to be

element1        A
element2        1
element3        2
element4       3^4

I am recieving exception
1 [Ljava.lang.String;@1786e64 with various ids after @

The commented code given below is creating problem.

CODE:

Scanner scanner = new Scanner(System.in);
str=scanner.nextLine();
System.out.println(str);
segments="(A)|(B)|(C)|(D)";
pipe="[\\s+\\|+\\+]";
carat="[\\^+]";
for(i=0;i<token_type1.length;i++)
{
token_type2=token_type1[i].toString().split(pipe);
for(j=0;j<token_type2.length;j++)
{           
/*
token_type3=token_type2.toString().split(carat);    
for(k=0;k<token_type3.length;k++)
System.out.println("\t"+(k+1)+" "+token_type3[k]);
*/
System.out.println((j+1)+"\t"+token_type2[j]);
}
System.out.println();
}

Please advise.

  • 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-15T20:17:19+00:00Added an answer on June 15, 2026 at 8:17 pm

    This will transform your input to your desired output (save the classes in two different files)

    Parser.java

    public class Parser {
    
        public static final String ELEMENT_DELIM_REGEX = "\\|";
    
        public static void main(String[] args) {
            String input = "A|1|2|3^4|";
            String[] tokens = input.split(ELEMENT_DELIM_REGEX);
            Element[] elements = new Element[tokens.length];
            for (int i = 0; i < tokens.length; i++) {
                elements[i] = new Element(i + 1, tokens[i]);
            }
            for (Element element : elements) {
                System.out.println(element);
            }
        }
    
    }
    

    and

    Element.java

    public class Element {
    
        public static final String SUB_ELEMENT_DELIM_REGEX = "\\^";
    
        private int number;
    
        private String[] content;
    
        public Element(int number, String content) {
            this.number = number;
            this.content = content.split(SUB_ELEMENT_DELIM_REGEX);
        }
    
        @Override
        public String toString() {
            if (content.length == 1) {
                return "Element " + number + "\t" + content[0];
            }
            StringBuilder str = new StringBuilder();
            for (int i = 0; i < content.length; i++) {
                str.append("Element " + number + "." + (i+1) + "\t" + content[i] + "\n");   
            }
            // Delete the last \n
            str.replace(str.length() - 1, str.length(), "");
            return str.toString();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I was able to figure out a timer earlier, but now I'm having
Okay, I thought I would be able to do this no problem, but for
Okay so I figured out the whole color business using HTML, but now when
Okay, Here is what I'm trying to do... Right now it is compiling but
Thanks to a previous answer , I'm now able to read my password-protected Word
Okay, so I know that using eval() isn't great, but I haven't been able
Okay, I've been trying to get this for almost 4 hours now, and it
Okay so right now I'm working on a program that has a whole bunch
Okay, I feel like I should be able to do this, but I have
Okay, so the answer to my question might not be the problem but here's

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.