Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Collection;

import java.util.Map;

public class Main {
    /**
     * This method does the same as getAllKeys, and while unused at the time of creation, may be useful for dotNet in the future.
     * The motivation for this method is that in dotNet, returning the keys as a Set requires constructing
     * a new object, whereas returning a collection does not -- so the custom implementation of this method in
     * dotNet is cheaper. Thus, this getAllKeysAsSimpleCollection method is preferable to getAllKeys even in Java, unless
     * the caller needs to call methods contains or containsAll in the resulting collection.
     *
     * In the latter case, i.e. calling code using contains or containsAll, using a Set in Java (i.e. method CollectionHelper.getAllKeys)
     * is preferable because methods contains (lowecase 'c') and containsAll are not available in dotNet's ICollection, only in
     * the ADHashSet. That being said, this is only the case if the method is not called frequently -- if it is, we
     * should add a CollectionHelper.containsKey method, and calling code should use it instead.
     */
    public static <K, V> Collection<K> getAllKeysAsSimpleCollection(Map<K, V> map) {
        return map.keySet();
    }
}