How to get a immutable collection from java HashMap?

前端 未结 5 670
一个人的身影
一个人的身影 2020-12-19 02:44

I need to get a collection from the java HashMap without the changes in the map reflecting in the collection later . I wanted to use Collection.toArray() to achieve this , b

5条回答
  •  春和景丽
    2020-12-19 03:04

    Its not possible to do this with a single API call, you need to utilize deep cloning. Clones won't be changed when you make changes to the original. This topic has been discussed on SO before, see How to clone ArrayList and also clone its contents? and Deep clone utility recomendation.

提交回复
热议问题