Java Array Contain ArrayContains(Object[] array, Object obj)

Here you can find the source of ArrayContains(Object[] array, Object obj)

Description

This methode returns, if array contains obj.

License

Apache License

Parameter

Parameter Description
array Array to be searched
obj Object to be found in the array

Return

true - obj found, false - nothing found

Declaration

public static boolean ArrayContains(Object[] array, Object obj) 

Method Source Code

//package com.java2s;
/*//  w  w  w .j  a  v  a 2  s .  c  o  m
 * Created on 26.04.2005
 *
 * Copyright 2005-2006 Daniel Jacobi
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

public class Main {
    /**
     * This methode returns, if array contains obj. If the array and object are
     * from incompatible types you also get a false, cause obj can not be found
     * in the array.
     * 
     * @param array
     *            Array to be searched
     * @param obj
     *            Object to be found in the array
     * @return <code>true</code> - obj found, <code>false</code> - nothing
     *         found
     */
    public static boolean ArrayContains(Object[] array, Object obj) {
        for (int i = 0; i < array.length; i++) {
            if (array[i].equals(obj)) {
                return true;
            }
        }

        return false;
    }
}

Related

  1. arrayContains(Object obj, Object[] array)
  2. arrayContains(Object[] a, Object ob)
  3. arrayContains(Object[] array, Object el)
  4. arrayContains(Object[] array, Object el)
  5. arrayContains(Object[] array, Object element)
  6. arrayContains(Object[] array, Object object)
  7. arrayContains(Object[] element, Object[][] array)
  8. arrayContains(Object[] haystack, Object needle)
  9. arrayContains(String[] arr, String sg, boolean ignoreCase)