Java tutorial
//package com.java2s; import java.util.Vector; public class Main { public static Vector<Integer> mergeSet(Vector<Integer> leftSet, Vector<Integer> rightSet, String mergeType) { if (leftSet == null || rightSet == null) return null; if (mergeType.trim().compareToIgnoreCase("or") == 0) { // OR set Vector<Integer> orSet = new Vector<Integer>(); orSet = leftSet; for (int i = 0; i < rightSet.size(); i++) { if (orSet.contains(rightSet.get(i)) == false) orSet.add(rightSet.get(i)); } return orSet; } else if (mergeType.trim().compareToIgnoreCase("and") == 0) { // AND // set Vector<Integer> andSet = new Vector<Integer>(); if (leftSet.size() > rightSet.size()) { for (int i = 0; i < rightSet.size(); i++) { if (leftSet.contains(rightSet.get(i)) == true) andSet.add(rightSet.get(i)); } } else { for (int i = 0; i < leftSet.size(); i++) { if (rightSet.contains(leftSet.get(i)) == true) andSet.add(leftSet.get(i)); } } return andSet; } else if (mergeType.trim().compareToIgnoreCase("xor") == 0) { // XoR // set // Left is Universal Set and right Set is getting Exclusive XoR Vector<Integer> xorSet = new Vector<Integer>(); for (int i = 0; i < leftSet.size(); i++) { if (rightSet.contains(leftSet.get(i)) == false) xorSet.add(leftSet.get(i)); } return xorSet; } return leftSet; } }