0

My string: result = order=7781&state=1&value=&add=114GH;

I want to get values:

String order = "7781";
String state = "1";
String value = "";
String add = "114GH";

Please help me to solve this problem! Thanks!

I have done till here, but its not working.

String[] resDetails = result.split("&");
for(String pair : resDetails)                       
        {
            String[] entry = pair.split("=");                    
            map.put(entry[0].trim(), entry[1].trim());        
        }

Its giving error because value is empty

ABD
  • 113
  • 3
  • 12
  • 1
    Possible duplicate of [Parse a URI String into Name-Value Collection](http://stackoverflow.com/q/13592236/5221149) – Andreas Jan 14 '17 at 06:52

1 Answers1

1

Change split("=") to split("=", -1), so trailing empty strings will not be discarded.

Andreas
  • 154,647
  • 11
  • 152
  • 247