0

I want to have an input as such

final String input = "one=1&two=2";

And I am using a Map method

public Map<String, String> decode(String s) {
    if(!s.isEmpty()){
        for(int i = 0; i < s.length(); i++) {
            s.split("&");
        }
    }
}

I am stuck here ,trying to write the algorithm that will check a string such as the one I wrote above and return mapping like

 ("one", "1");
 ("two", "2");

I wrote a regex like this ^[a-z0-9 +=][{1,}]$

3
  • 1) Thre is no point to iterate over the string. 2) Keep it simple and just split string with "&" and then with "=". Commented Nov 17, 2017 at 21:08
  • And how do I return the value to give the desired result Commented Nov 17, 2017 at 21:54
  • The linked duplicate answer has the necessary code for you. Look at the splitQuery method. Commented Nov 17, 2017 at 23:08

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.