Get all the entries in the Map object out and place into the List passed in, just add at the bottom. - Java java.util

Java examples for java.util:List Operation

Description

Get all the entries in the Map object out and place into the List passed in, just add at the bottom.

Demo Code

/*// w  w w .java  2s. co  m
 * Copyright 2006 - Gary Bentley
 *
 * 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.
 */
//package com.java2s;
import java.util.Map;
import java.util.List;

import java.util.Iterator;

public class Main {
    /**
     * Get all the entries in the Map object out and place into
     * the List passed in, just add at the bottom.
     *
     * @param map The Map to get objects out of.
     * @param list The List to add objects to the end of.  We add the
     *             Map.Entry.
     */
    public static void addMapEntriesToList(Map map, List list) {

        Iterator iter = map.entrySet().iterator();

        while (iter.hasNext()) {

            list.add(((Map.Entry) iter.next()).getValue());

        }

    }
}

Related Tutorials