title: how to copy a dictionary in another java
body: <p>I have 2 dictionaries and I want to make a copy from the first one in the second and then the ways of each other to be different.Here is the adt of my dictionaries implemented:</p>
  
  <pre><code>public class CollectionDic1&lt;K,Integer&gt;  implements Id&lt;K,Integer&gt; , Serializable{
  private K key;
  private Integer value;
  private Map&lt;K,Integer&gt; dict;
  
  public CollectionDic1(){
      dict = new HashMap&lt;K,Integer&gt;();
  }
  
  public void put(K key, Integer value){
      dict.put(key, value);
  }
  public int getSize(){
      return dict.size();
  }
  public K getKey(){ return key; }
  public Integer getValue(){return value;}
  public void remove(K key){
      try{
          if (isEmpty())
              throw new ExceptionRepo();
          else
              dict.remove(key);
  
      }catch (ExceptionRepo ex){
              System.err.println("Error: Dictionary is empty.");
  
      }
  
  }
  
  public boolean isEmpty(){
      return dict.isEmpty();      
  }
  
  public Integer get(K k){
      return dict.get(k);
  }
  
  public boolean containsKey(K k){
      return dict.containsKey(k);     
  }
  
  public void update (K k, Integer v){
      dict.put(k, v);
  }
  public String toString(){
      Set&lt;K&gt; all = dict.keySet();
      Object[] keysA = all.toArray();
      String res = "";
      for (int i=0; i&lt;dict.size();i++){
          Integer v = dict.get(keysA[i]);
          res += keysA[i].toString() + " : " + v.toString() + "\r\n";         
      }
      return res;
  
  }
  
  }
  </code></pre>
  
  <p>And here I tried to do:</p>
  
  <pre><code>public void execute{
        //prg is unimportant
        Id&lt;Object,Integer&gt; first= prg.getDict();
        Id&lt;Object,Integer&gt; second = new CollectionDic1&lt;Object,Integer&gt;();
        for (int i=0; i&lt;first.getSize(); i++){
            second.put(first.getKey(), first.getValue());
        }
  </code></pre>
  
  <p>In for I want to add the keys and the values already existing in the first dictionary but I don't know how.Any ideas? </p>