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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:33:34+00:00 2026-05-30T12:33:34+00:00

I have a method that generates pop-up menu with many submenus. Basically these menus

  • 0

I have a method that generates pop-up menu with many submenus. Basically these menus given dynamically so I have to have algorithm to handle creating submenus using below string.
In order to do it I will need to transform this string into Java Tree by splitting using the delimiter. I am stuck on how to handle splitted string data and translate to the Java Tree Model according to Parent and children nodes.

An Example of Dynamic String Values that I need to parse:

String str = ” Menu1; Menu2; [Menu2A; Menu2B; [Menu2B-A; Menu2B-B];]; Menu3; “;

After Handling operation The output should be:

                                 Pop-up Menu
                                 /    |     \
                           Menu1    Menu2   Menu3
                                 /     | 

                              Menu2A     Menu2B
                                          |       \
                                          |        \
                                       Menu2B-A  Menu2B-B
  • 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-05-30T12:33:36+00:00Added an answer on May 30, 2026 at 12:33 pm

    You could do something like:

    • Traverse the string from left to right, collecting characters into a current string variable.
    • If you encounter a ; put the current string in a data structure holding (level, array of menu entries for level).
    • If you encounter a [ call recursively with the rest of the string and level + 1.
    • If you encounter a ] return.

    Some approximate Java code:

    private int parseString(String input, String parent, 
                            Map<String, ArrayList<String>> levels) {
    
         StringBuilder currentString = new StringBuilder();
         int index = 0;
         while(index < input.length()) {
             char c = input.charAt(index);
    
             if(c == ' ') { // ignore spaces
                 index++;
                 continue;
             }
    
             if(c == ';') { // end of menu entry, add to the list
                 if(!currentString.toString().isEmpty()) {
                     levels.put(currentString.toString(), new ArrayList<String>());             
                     levels.get(level).add(currentString.toString());
                 }
                 currentString.delete(0, currentString.length());
                 index++;
                 continue;
             }
    
             if(c == ']') { // end of sublist, return
                 return index + 1;
             }
    
             if(c == '[') { // start of sublist, recursive call
                 int temp = parseString(input.substring(index + 1), 
                                        levels.get(parent).get(levels.get(parent).size() - 1), levels);
                 index += temp;
                 index++;
                 continue;
             }
    
             currentString.append(c);
             index++;             
         }
         return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a factory method that generates django form classes like so: def get_indicator_form(indicator,
I have a c++ plus method that generates a value. i am calling this
I have a method that generates XML for a class I have created -getXML().
I have a method that generates and error that a int was expected but
In Java, a for-each loop. If I have a method that generates an array,
So I have method that generates a barcode and label with that barcode. We
Context: C# 3.0, .Net 3.5 Suppose I have a method that generates random numbers
Ok, so I have an action method that generates a PDF and returns it
I have written an O/R database wrapper that generates some wrapper methods for stored
I have class method that returns a list of employees that I can iterate

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.