Here you can find the source of unionSets(ArrayList
Parameter | Description |
---|---|
s1 | set s1 |
s2 | set s2 |
public static ArrayList<Integer> unionSets(ArrayList<Integer> s1, ArrayList<Integer> s2)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { /**//from w w w. j a va 2s . co m * union two sets s1 and s2 * * @param s1 * set s1 * @param s2 * set s2 * @return the union of two sets */ public static ArrayList<Integer> unionSets(ArrayList<Integer> s1, ArrayList<Integer> s2) { if (s2 == null) { return s1; } for (Integer i : s2) { if (!s1.contains(i)) { s1.add(i); } } return s1; } }