Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {

    public static <T> Set<T> union(Set<T> set1, Set<T> set2) {
        if (set1 == null || set2 == null) {
            return (set1 == null) ? new HashSet<T>(set2) : new HashSet<T>(set1);
        }
        Set<T> ret = new HashSet<T>(set1);
        ret.addAll(set2);
        return ret;
    }

    public static <T> List<T> union(List<T> list1, List<T> list2, boolean duplicate) {
        if (list1 == null || list2 == null) {
            return (list1 == null) ? new ArrayList<T>(list2) : new ArrayList<T>(list1);
        }
        List<T> ret;
        if (duplicate) {
            ret = new ArrayList<T>(list1);
            ret.addAll(list2);
        } else {
            Set<T> set = union(new HashSet<T>(list1), new HashSet<T>(list2));
            ret = new ArrayList<T>(set);
        }
        return ret;
    }
}