java里面 put方法的问题

hashmap V put(K key,
V value) 返回的v是什么类型

第1个回答  推荐于2017-09-01
* @return the previous value associated with <tt>key</tt>, or
* <tt>null</tt> if there was no mapping for <tt>key</tt>.
* (A <tt>null</tt> return can also indicate that the map
* previously associated <tt>null</tt> with <tt>key</tt>.)
返回的V是个Object ,根据您在上一次put的值的类型来决定。
比如,您上一次put一个String:map.put("1", "test1");
那么当您第二次put的时候 Object v = map.put("1", "test2"); 返回的应该是上一次的String: "test1"本回答被提问者采纳
第2个回答  2012-03-18
自己写代码验证一下就知道啦。
第3个回答  2012-03-18
key,是这个的类型
相似回答