美文网首页计算机
Java - How to deep copy HashSet,

Java - How to deep copy HashSet,

作者: Richardo92 | 来源:发表于2016-09-28 06:25 被阅读199次

Deep copy HashSet

HashSet<Integer> set = new HashSet<Integer>();
HashSet<Integer> set2 = new HashSet<Integer>();
set2.addAll(set);

or

HashSet<Integer> set = new HashSet<Integer>();
HashSet<Integer> set2 = new HashSet<Integer>(set);

Deep copy HashMap

HashMap<Integer, Integer> map = new HashMap<>();
HashMap<Integer, Integer> map2 = new HashMap<>();
map2.putAll(map);

or

HashMap<Integer, Integer> map = new HashMap<>();
HashMap<Integer, Integer> map2 = new HashMap<>(map);

Anyway, Good luck, Richardo! -- 09/27/2016

相关文章

  • Java - How to deep copy HashSet,

    Deep copy HashSet or Deep copy HashMap or Anyway, Good lu...

  • Java------List的深拷贝与浅拷贝

    Java的浅拷贝(Shallow Copy)、深拷贝(Deep Copy)。 浅拷贝(Shallow Copy) ...

  • java 中 deep copy & shallow copy

    1. 写在前面 今天遇到了这样一个问题,事实上这个问题是之前遇到过的。java 中列表的赋值的问题。这个问题核心是...

  • OC基础

    Difference between shallow copy and deep copy?1> 浅拷贝:指...

  • 转载:[题]

    Difference between shallow copy and deep copy?1> 浅拷贝:指针(地...

  • HashSet详解

    引用 java中HashSet详解 Java 编程下 HashSet 存入相同元素的原理 1.向HashSet 集...

  • Deep Link on Facebook

    How to use App Links to Deep Link on Facebook How to Use ...

  • HashSet的用法

    java集合——HashSet的用法 一、HashSet的构造 二、HashSet添加元素 三、遍历HashSet...

  • shallow copy & deep copy

    浅拷贝:只复制指向对象的指针,而不复制引用对象本身。在另一个地方用同一个指针引用该对象。 深拷贝:复制引用对象本身...

  • Shallow Copy & Deep Copy

    对象的拷贝需要首先实现协议浅拷贝:object A和ob...

网友评论

本文标题:Java - How to deep copy HashSet,

本文链接:https://www.haomeiwen.com/subject/dpshyttx.html