Here you can find the source of arraysIntersect(Object[] array1, Object[] array2)
Parameter | Description |
---|---|
array1 | first object array |
array2 | second object array |
public static boolean arraysIntersect(Object[] array1, Object[] array2)
//package com.java2s; /**//from w ww .j a va 2 s .co m * Copyright (C) 2014 WING, NUS and NUS NLP Group. * * This program is free software: you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If * not, see http://www.gnu.org/licenses/. */ public class Main { /** * Check if two arrays have at least one common element. * * @param array1 first object array * @param array2 second object array * @return Returns {@code true} if the arrays have one or more common elements */ public static boolean arraysIntersect(Object[] array1, Object[] array2) { boolean intersect = false; for (int i = 0; i < array1.length && !intersect; ++i) { Object e1 = array1[i]; if (e1 != null) { for (int j = 0; j < array2.length && !intersect; ++j) { Object e2 = array2[j]; intersect = e1.equals(e2); } } } return intersect; } }