Here you can find the source of ArrayContains(Object[] array, Object obj)
Parameter | Description |
---|---|
array | Array to be searched |
obj | Object to be found in the array |
true
- obj found, false
- nothing found
public static boolean ArrayContains(Object[] array, Object obj)
//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; } }