开发者

Implementation of associative array [closed]

It's difficult to tell what is being aske开发者_JAVA百科d here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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]}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜