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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:20:50+00:00 2026-06-14T21:20:50+00:00

I get following strings from a server, only separated by spaces. (Line breaks are

  • 0

I get following strings from a server, only separated by spaces. (Line breaks are just due to readability, “XX is a placeholder and can vary in length. also the length of the things in square brackets can vary in length.

String 1:

status:ok [XXX][a=XXX b=XXX c=XXX d=XXX e=0 f=XXX g=XXX h=XXX i=XXX j=XXX 
k=XXX l=XXX m=XXX n=[[XXX][XXX]] p=[[XXX][XXX][XXX][XXX][XXX][XXX][XXX]]]
end:end

String 2:

status:ok [XXX][a=XXX b=XXX  c=XXX d=XXX d2=XXX e=XXX  f=XXX g=XXX h=XXX i=XXX j=XXX 
k=XXX l=XXX m=XXX n=[[XXX][XXX]] p=[[XXX][XXX][XXX][XXX][XXX][XXX][XXX]]]
end:end

All parts in square brackets “[]” can contain more or less of “[]”-elements and words inside a inner “[]” can vary in length. I need those a,b,c,d,e etc. in a HashMap, but before i can do that i need to parse it somehow.

How can i parse this string efficiently in Java?

I have searched and found lots of websites and threads where people suggested something called “key value parsing” apart from “Regex parsing”, but unfortunately information on “key value parsing” is sparse.

EDIT:
In the end I want to store those values in a Hashmap like this:

HashMap<String,Object> myHashMap = new HashMap();
myHashMap.put(a, XXX);
....
myHashMap.put(p,array-of-all-[XXX]);
  • 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-14T21:20:51+00:00Added an answer on June 14, 2026 at 9:20 pm

    You could simply do this and it will print your a,b,c ..

      String s ="status:ok [XXX][a=XXX b=XXX c=XXX d=XXX e=0 f=XXX g=XXX h=XXX i=XXX j=XXX k=XXX l=XXX m=XXX n=[[XXX][XXX]] p=[[XXX][XXX][XXX][XXX][XXX][XXX][XXX]]] end:end".replaceAll("end:end", "");
    
        String [] ss  = s.split("=");
        HashMap<Character,Object> myHashMap = new HashMap();
        try{
        for(int i=0;i<ss.length;i++){
    
            myHashMap.put(ss[i].charAt(ss[i].length()-1), ss[i+1].substring(0, ss[i+1].length()-1).trim());
    
        }
    
        }catch(Exception e){
            // do nothing
        }
          System.out.println(myHashMap);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From a server, I get strings of the following form: String x = fixedWord1:var1
How can I get the connection.connection_string value from the following hibernate xml file using
I get the following text as a string from an XML-based REST API 'd':4
I have following syntax in my script to get email address from string. The
i am using following webservices for retrieving data from server server side:.net client side:ksoap2
I receive data in the following format from the server <ul> <li>Some text</li> <li>Other
I am getting the following error response from the server. HTTP Status 500 -
I am trying to insert a time only value, but get the following error
I am following a tutorial to download file from server. But having some trouble.
I have the following string fromat: session=11;reserID=1000001 How to get string array of number?

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.