请求地址:http://localhost:8080/yhrecord/projman/test.jsp?name=sky&age=12 Map<String,String> map=request.getParameterMap(); Set<Map.Entry<String, String>> entry=map.entrySet(); for(Map.Entry<String,String> entry_:entry){ System.out.println(entry_.getKey().toString()+":"+entry_.getValue().toString()); } System.out.println(entry_.getKey().toString()+”:”+entry_.getValue().toString()); 请问怎么破。。。 |
|
貌似request.getParameterMap() 返回的是个Map<String,String[]>
不是Map<String,String>吧 所以强转报错了 |
|
不是你说的这样的 这个是eclipse中提示的api Set<Entry<String, String>> java.util.Map.entrySet() Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator""s own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations. Returns: a set view of the mappings contained in this map |
|
你说的这个跟我的 好像不是一码事。。 我这个是request中的。。 |
|
Map<String,String> map=request.getParameterMap(); |
|
getParameterMap public Map getParameterMap() The default behavior of this method is to return getParameterMap() on the wrapped request object. Specified by: getParameterMap in interface ServletRequest Returns: an immutable java.util.Map containing parameter names as keys and parameter values as map values. The keys in the parameter map are of type String. The values in the parameter map are of type String array. The values in the parameter map are of type String array. Map<String, String[]> map = request.getParameterMap(); Set<Map.Entry<String, String[]>> entry = map.entrySet(); |
|
30分 |
import java.util.HashMap; import java.util.Map; import java.util.Set; public class Test17 { public static void main(String[] args) { Map<String, String[]> map = new HashMap<String,String[]>(); map.put("B", new String[]{"B","C","D"}); map.put("A", new String[]{"B","C","D"}); Set<Map.Entry<String, String[]>> entry = map.entrySet(); for (Map.Entry<String, String[]> entry_ : entry) { System.out.println(entry_.getKey().toString() + ":" + java.util.Arrays.toString(entry_.getValue())); } } } |
import java.util.HashMap; import java.util.Map; import java.util.Set; public class Test17 { public static void main(String[] args) { Map<String, String[]> map = new HashMap<String,String[]>(); map.put("B", new String[]{"B","C","D"}); map.put("A", new String[]{"B","C","D"}); Set<Map.Entry<String, String[]>> entry = map.entrySet(); for (Map.Entry<String, String[]> entry_ : entry) { System.out.println(entry_.getKey().toString() + ":" + java.util.Arrays.toString(entry_.getValue())); } } } 谢谢你 ,@shixitong 。你这个可以 但是我想问 entry_.getValue() 得到的是内存地址 怎么得到真实值。。 |
|
谢谢你 ,@shixitong
已经知道了 entry_.getValue()[0] 这个得到的是数组。。 |
|
为什么说是内存地址,依据是什么,java里是得不到内存地址的 |