Java Map Clone cloneMap(Map orig)

Here you can find the source of cloneMap(Map orig)

Description

Shallow clone

License

Apache License

Declaration

public static <K, V> Map<K, V> cloneMap(Map<K, V> orig) 

Method Source Code

//package com.java2s;
/*/*from   w w w  .  j  a  va  2  s. c o  m*/
 * Copyright (c) 2010-2013 Evolveum
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.HashMap;

import java.util.Map;
import java.util.Map.Entry;

public class Main {
    /**
     * Shallow clone
     */
    public static <K, V> Map<K, V> cloneMap(Map<K, V> orig) {
        if (orig == null) {
            return null;
        }
        Map<K, V> clone = new HashMap<K, V>();
        for (Entry<K, V> origEntry : orig.entrySet()) {
            clone.put(origEntry.getKey(), origEntry.getValue());
        }
        return clone;
    }
}

Related

  1. clone(Map origMap)
  2. clone(Map map)
  3. cloneDefaults(Map defaults)
  4. cloneMap(final Map m)
  5. cloneMap(Map map)
  6. cloneMap(Map> map)