Java Array Contain arrayContains(Object[] a, Object ob)

Here you can find the source of arrayContains(Object[] a, Object ob)

Description

Returns the index of ob in array a

License

Open Source License

Return

-1 if ob is not in a

Declaration

public static int arrayContains(Object[] a, Object ob) 

Method Source Code

//package com.java2s;
/* //from ww w  . j av  a 2s . c  om
 GeoGebra - Dynamic Mathematics for Everyone
 http://www.geogebra.org
    
 This file is part of GeoGebra.
    
 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.
     
 */

public class Main {
    /**
     * Returns the index of ob in array a
     * @return -1 if ob is not in a
     */
    public static int arrayContains(Object[] a, Object ob) {
        if (a == null)
            return -1;
        for (int i = 0; i < a.length; i++) {
            if (a[i] == ob)
                return i;
        }
        return -1;
    }
}

Related

  1. arrayContains(int[] arr, int e)
  2. arrayContains(int[] arr, int ii)
  3. arrayContains(int[] array, int value)
  4. arrayContains(int[] array, int value)
  5. arrayContains(Object obj, Object[] array)
  6. arrayContains(Object[] array, Object el)
  7. arrayContains(Object[] array, Object el)
  8. arrayContains(Object[] array, Object element)
  9. ArrayContains(Object[] array, Object obj)