Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.Collections;

import java.util.Set;
import java.util.WeakHashMap;
import com.google.common.collect.Sets;

public class Main {
    /**
     * There is currently no class in Java for a weak set, but it can be created as a set wrapping a weak map as in the body of the method below.
     * @return a weak set
     */
    public static <T> Set<T> createWeakSet() {
        return Collections.newSetFromMap(new WeakHashMap<T, Boolean>());
    }

    public static <T> Set<T> createWeakSet(Iterable<T> items) {
        Set<T> set = createWeakSet();
        set.addAll(Sets.newHashSet(items));
        return set;
    }
}