java中的HashMap克隆实用程序 [英] clone utility for HashMap in java

查看:80
本文介绍了java中的HashMap克隆实用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有java实用程序为 HashMap 执行 clone()方法,以便它复制地图元素不只是地图对象(在 HashMap 类中作为 clone()?)

Is there java utility that does clone() method for HashMap such that it does copy of the map elements not just the map object (as the clone() in HashMap class)?

推荐答案

元素中提到的其他对象怎么样?您希望克隆有多深?

What about other objects referred to in the elements? How deep do you want your clone?

如果您的地图元素没有任何深层引用和/或所有内容都是 Serializable ,您可以通过 ObjectOutputStream 将地图序列化为 ByteArrayOutputStream ,然后立即反序列化。

If your map elements don't have any deep references and/or everything is Serializable, you can serialize the map via ObjectOutputStream into a ByteArrayOutputStream and then deserialize it right away.

唯一的另一种选择是手动完成。

The only other alternative is to do it manually.

这篇关于java中的HashMap克隆实用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆