Bytes Class | Guava | Java Last Updated : 20 Nov, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report Bytes is a utility class for primitive type byte. It provides Static utility methods pertaining to byte primitives, that are not already found in either Byte or Arrays and interpret bytes as neither signed nor unsigned. The methods which specifically treat bytes as signed or unsigned are found in SignedBytes and UnsignedBytes. Declaration : @GwtCompatible(emulated=true) public final class Bytes extends Object Below table shows the methods provided by Guava Bytes Class : Exceptions : ensureCapacity : IllegalArgumentException if minLength or padding is negative. toArray : NullPointerException if collection or any of its elements is null. Below given are some examples showing the implementation of Guava Bytes Class methods : Example 1 : Java // Java code to show implementation // of Guava Bytes.asList() method import com.google.common.primitives.Bytes; import java.util.*; class GFG { // Driver method public static void main(String[] args) { byte arr[] = { 3, 4, 5, 6, 7 }; // Using Bytes.asList() method which convert // array of primitives to array of objects List<Byte> myList = Bytes.asList(arr); // Displaying the elements System.out.println(myList); } } Output : [3, 4, 5, 6, 7] Example 2 : Java // Java code to show implementation // of Guava Bytes.indexOf() method import com.google.common.primitives.Bytes; import java.util.*; class GFG { // Driver method public static void main(String[] args) { byte[] arr = { 3, 4, 5, 6, 7 }; // Displaying the index for // first occurrence of given target System.out.println(Bytes.indexOf(arr, (byte)5)); } } Output : 2 Example 3 : Java // Java code to show implementation // of Guava Bytes.concat() method import com.google.common.primitives.Bytes; import java.util.*; class GFG { // Driver method public static void main(String[] args) { byte[] arr1 = { 3, 4, 5 }; byte[] arr2 = { 6, 7 }; // Using Bytes.concat() method which // combines arrays from specified // arrays into a single array byte[] arr = Bytes.concat(arr1, arr2); // Displaying the elements System.out.println(Arrays.toString(arr)); } } Output : [3, 4, 5, 6, 7] Example 4 : Java // Java code to show implementation // of Guava Bytes.contains() method import com.google.common.primitives.Bytes; class GFG { // Driver method public static void main(String[] args) { byte[] arr = { 3, 4, 5, 6, 7 }; // Using Bytes.contains() method which // checks if element is present in array // or not System.out.println(Bytes.contains(arr, (byte)8)); System.out.println(Bytes.contains(arr, (byte)7)); } } output : false true Example 5 : Java // Java code to show implementation // of Guava Bytes.lastIndexOf() method import com.google.common.primitives.Bytes; class GFG { // Driver method public static void main(String[] args) { byte[] arr = { 3, 4, 5, 6, 7, 5, 5 }; // Using Bytes.lastIndexOf() method // to get last occurrence of given target System.out.println(Bytes.lastIndexOf(arr, (byte)5)); } } Output : 6 Example 6 : Java // Java code to show implementation // of Guava Bytes.lastIndexOf() method import com.google.common.primitives.Bytes; class GFG { // Driver method public static void main(String[] args) { byte[] arr = { 3, 4, 5, 6, 7, 5, 5 }; // Using Bytes.lastIndexOf() method // to get last occurrence of given target // here target i.e, 9 is not present in // array arr, so -1 will be returned System.out.println(Bytes.lastIndexOf(arr, (byte)9)); } } Output : -1 Comment More infoAdvertise with us Next Article Chars Class | Guava | Java S Sahil_Bansall Follow Improve Article Tags : Java Practice Tags : Java Similar Reads Booleans Class | Guava | Java Booleans is a utility class for primitive type Boolean. It provides Static utility methods pertaining to boolean primitives, that are not already found in either Boolean or Arrays. Declaration : @GwtCompatible(emulated=true) public final class Booleans extends Object Below given are some methods pro 3 min read Chars Class | Guava | Java Chars is a utility class for primitive type char. It provides Static utility methods pertaining to char primitives, that are not already found in either Character or Arrays. All the operations in this class treat char values strictly numerically, i.e, they are neither Unicode-aware nor locale-depend 3 min read CharMatcher Class | Guava | Java CharMatcher determines a true or false value for any Java char value. This class provides various methods to handle various Java types for char values. Declaration: The declaration for com.google.common.base.CharMatcher is as: @GwtCompatible(emulated = true) public final class CharMatcher extends Ob 3 min read Java.Lang.Byte class in Java In Java, Byte class is a wrapper class for the primitive type byte which contains several methods to effectively deal with a byte value like converting it to a string representation, and vice-versa. An object of the Byte class can hold a single byte value. Constructors of Byte Class There are mainly 6 min read BigIntegerMath Class | Guava | Java BigIntegerMath is used to perform mathematical operations on BigInteger values. Basic standalone math functions are divided into the classes IntMath, LongMath, DoubleMath, and BigIntegerMath based on the primary numeric type involved. These classes have parallel structure, but each supports only the 3 min read Ints Class | Guava | Java Ints is a utility class for primitive type int. It provides Static utility methods pertaining to int primitives, that are not already found in either Integer or Arrays. Declaration : @GwtCompatible(emulated=true) public final class Ints extends Object Below table shows the Field summary for Guava In 3 min read Like