import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

public class Solution {

    public int[] intersection(int[] nums1, int[] nums2) {

        Set<Integer> set = new HashSet<Integer>();
        ArrayList<Integer> intersect = new ArrayList<Integer>();

        for (int i = 0; i < nums1.length; i++) {
            set.add(nums1[i]);
        }

        for (int i = 0; i < nums2.length; i++) {

            if (set.contains(nums2[i])) {

                intersect.add(nums2[i]);
                set.remove(nums2[i]);

            }

        }

        int[] result = new int[intersect.size()];

        for (int i = 0; i < intersect.size(); i++) {
            result[i] = intersect.get(i);
        }

        return result;

    }

}

Create : 349 Intersection of Two Arrays