Java Guava | Bytes.contains() method with Examples
Bytes.contains() method of Guava’s Bytes Class accepts two parameters array and target. The method is used to check if the target element is present in the array or not.
public static boolean contains(byte array, byte target)
Parameters: The method accepts two parameters :
- array: An array of byte values, possibly empty.
- target: A primitive byte value which is to be checked if it is present in the array or not.
Return Value: The method returns true if target is present as an element anywhere in array, and returns false if the target is not present anywhere in the array.
Exceptions: The method does not throw any exceptions.
Below examples illustrate the implementation of above method:
Target is present in the array
Example 2 :
Target is not present in the array
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.