集册 Java实例教程 搜索“objects”数组中的任何对象是否等于“another object”。

搜索“objects”数组中的任何对象是否等于“another object”。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

563
搜索“objects”数组中的任何对象是否等于“another object”。

/*******************************************************************************

 * Copyright (c) 2010 SAP AG.

 * All rights reserved. This program and the accompanying materials

 * are made available under the terms of the Eclipse Public License v1.0

 * which accompanies this distribution, and is available at

 * http://www.eclipse.org/legal/epl-v10.html

 *

 * Contributors:

 *    Emil Simeonov - initial API and implementation.

 *    Dimitar Donchev - initial API and implementation.

 *    Dimitar Tenev - initial API and implementation.

 *    Nevena Manova - initial API and implementation.

 *    Georgi Konstantinov - initial API and implementation.

 *    Jakob Spies - initial API and implementation.

 *******************************************************************************/
 /** 
  来自 时 代      J a v a   公   众 号 - nowjava.com**/

import java.util.ArrayList;

import java.util.Collection;

import java.util.Collections;

import java.util.HashSet;

import java.util.LinkedList;

import java.util.List;

import java.util.Set;


public class Main{

    public static void main(String[] argv){

        Object objects = "nowjava.com";

        Object searchForObject = "nowjava.com";

        System.out.println(containsObject(objects,searchForObject));

    }

    /**

     * Search whether any object in 'objects' array does equal 'searchForObject'.

     * @param objects can be null, and can contain null values

     * @param searchForObject can be null

     * @return true if searchForObject is found in 'objects'

     */

    public static boolean containsObject(Object objects[],

            Object searchForObject) {/** 来 自 时 代 J a v a**/

        if (objects == null) {

            return false;
展开阅读全文