Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006, 2014 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Mike Kucera (IBM Corporation) - initial API and implementation
 *     Sergey Prigogin (Google)
 *     Nathan Ridge
 *******************************************************************************/

import java.util.ArrayList;

import java.util.List;

import java.util.Map;

public class Main {
    /**
     * Returns a List<U> corresponding to a T in a Map<T, List<U>>. If the mapping doesn't exist,
     * creates it with an empty list as the initial value.
     * @since 5.6
     */
    public static <T, U> List<U> listMapGet(Map<T, List<U>> m, T t) {
        List<U> result = m.get(t);
        if (result == null) {
            result = new ArrayList<U>();
            m.put(t, result);
        }
        return result;
    }
}