Java Map Put putAll(final Map dst, final Map src)

Here you can find the source of putAll(final Map dst, final Map src)

Description

Put all entries from the source Map into the destination Map, converting keys and values to Strings if needed

License

Open Source License

Parameter

Parameter Description
dst the destination Map
src the source Map
K the source key type
V the source value type

Declaration

public final static <K, V> void putAll(final Map<String, String> dst, final Map<K, V> src) 

Method Source Code

//package com.java2s;
/**/*  ww  w  .ja  v a 2  s. co m*/
 * The contents of this file are subject to the Regenstrief Public License
 * Version 1.0 (the "License"); you may not use this file except in compliance with the License.
 * Please contact Regenstrief Institute if you would like to obtain a copy of the license.
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) Regenstrief Institute.  All Rights Reserved.
 */

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

public class Main {
    /**
     * Put all entries from the source Map into the destination Map, converting keys and values to
     * Strings if needed
     * 
     * @param dst the destination Map
     * @param src the source Map
     * @param <K> the source key type
     * @param <V> the source value type
     **/
    public final static <K, V> void putAll(final Map<String, String> dst, final Map<K, V> src) {
        final Iterator<Entry<K, V>> iter = src.entrySet().iterator();

        while (iter.hasNext()) {
            final Entry<K, V> entry = iter.next();
            dst.put(toString(entry.getKey()), toString(entry.getValue()));
        }
    }

    public final static <E> Iterator<E> iterator(final Iterable<E> iterable) {
        return iterable == null ? null : iterable.iterator();
    }

    public final static boolean hasNext(final Iterator<?> i) {
        return (i != null) && i.hasNext();
    }

    /**
     * Converts an object to a string
     * 
     * @param o the Object to convert
     * @return the String
     **/
    public final static String toString(final Object o) {
        return o == null ? null : o.toString();
    }
}

Related

  1. put(Map map, String key, Object value)
  2. put(Map structure, String name, Object object)
  3. put(ThreadLocal> threadLocal, Object key, String value)
  4. put2DayOfWeekMaps(int pDayOfWeek, String pDayName)
  5. putAbsent(Map dest, Map src)
  6. putAll(M map, Iterable> values)
  7. putAll(Map original, Map... others)
  8. putAll(Map dest, Collection src, V value)
  9. putAll(Map map, Map otherMap)