作者zeebra (Be Bop)
看板java
标题[问题] 请问一个关於Map的问题
时间Thu May 25 13:15:17 2006
关於Map以TreeMap为例
我的目的是想将TreeMap A的所有内容复制到TreeMap B
但对於TreeMap有三个方法我有些问题
第一个为建构子
TreeMap(Map m)
Constructs a new map containing the same mappings as the given map,
sorted according to the keys' natural order.
第二个为putAll方法
putAll(Map map)
Copies all of the mappings from the specified map to this map.
以上这两个方法我试过之後
发现他们是复制记忆体的位置 也就是说 使用TreeMap B = new TreeMap(A)
是复制reference 若使用B.putAll(A)的道的结果似乎也相同 也是复制reference
有什麽方法是可以复制内容而不是复制reference的呢??
另外 TreeMap的clone方法是做什麽用的呢?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.216.216.87