Implementation of associative array [closed]
write a function which decodes a URL-encoded string into an associative array. If there are two parameters with same name, the value should be stacked as an array.
For example, the string
a=1&b=2&a=hello&apple=9&apple=digital
would be converted to the associative array:
array( 'a' => array(1,'hello'), 'b'=> 2, 'apple' => array(9,'digital') )
Consider using Map<String, ArrayList<String>>
For example:
Map<String, ArrayList<String>> m = new HashMap<String, ArrayList<String>>();
ArrayList<String> arr = new ArrayList<String>();
arr.add("value1");
arr.add("value2");
m.put("key", arr);
System.out.println(m); // {key=[value1, value2]}
精彩评论