Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: LGPL 

import java.util.Collection;

import java.util.HashSet;

import java.util.Set;
import java.util.TreeSet;

public class Main {
    public static <T> Set<T> getSortedIntersectionValues(Collection<T> colection1, Collection<T> colection2) {
        Set<T> set = new TreeSet<>();
        set.addAll(getIntersectionValues(colection1, colection2));
        return set;
    }

    public static <T> Set<T> getIntersectionValues(Collection<? extends T> colection1,
            Collection<? extends T> colection2) {

        Set<T> ret = new HashSet<T>();
        if (colection1 == null || colection2 == null)
            return ret;

        for (T value : colection1) {
            if (colection2.contains(value))
                ret.add(value);
        }
        return ret;
    }
}