如果目标在数组中的任何位置作为元素存在,则 Guava 的Ints.contains()返回true。
用法:
public static boolean contains(int[] array, int target)
参数:此方法接受以下参数:
- array:一个int值数组,可能为空。
- target:基本的int值。
返回值:此方法返回一个布尔值。如果array [i] ==目标i的某个值,则返回True。
范例1:
// Java code to show implementation of
// Guava's Ints.contains() method
import com.google.common.primitives.Ints;
import java.util.Arrays;
class GFG {
// Driver's code
public static void main(String[] args)
{
// Creating an Integer array
int[] arr = { 5, 4, 3, 2, 1 };
int target = 3;
// Using Ints.contains() method to search
// for an element in the array. The method
// returns true if element is found, else
// returns false
if (Ints.contains(arr, target))
System.out.println("Target is present"
+ " in the array");
else
System.out.println("Target is not present"
+ " in the array");
}
}
输出:
Target is present in the array
范例2:
// Java code to show implementation of
// Guava's Ints.contains() method
import com.google.common.primitives.Ints;
import java.util.Arrays;
class GFG {
// Driver's code
public static void main(String[] args)
{
// Creating an Integer array
int[] arr = { 2, 4, 6, 8, 10 };
int target = 7;
// Using Ints.contains() method to search
// for an element in the array. The method
// returns true if element is found, else
// returns false
if (Ints.contains(arr, target))
System.out.println("Target is present"
+ " in the array");
else
System.out.println("Target is not present"
+ " in the array");
}
}
输出:
Target is not present in the array
相关用法
- Java Guava Ints max()用法及代码示例
- Java Guava Ints min()用法及代码示例
- Java Guava Ints lastIndexOf()用法及代码示例
- Java Guava Ints indexOf()用法及代码示例
- Java Guava Ints join()用法及代码示例
- Java Guava Ints toArray()用法及代码示例
- Java Guava Ints concat()用法及代码示例
- Java Guava Ints asList()用法及代码示例
- Java Guava Ints.hashCode()用法及代码示例
- Java Guava Ints.compare()用法及代码示例
- Java Ints.indexOf(int[] array, int[] target)用法及代码示例
- Java Guava Sets union()用法及代码示例
- Java Guava Sets difference()用法及代码示例
- Java Guava BigIntegerMath binomial()用法及代码示例
注:本文由纯净天空筛选整理自Sahil_Bansall大神的英文原创作品 Ints contains() function | Guava | Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。