Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

clone utility for HashMap in java

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)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...