Guava - Bytes Class - Guava

Bytes is a utility class for primitive type byte.

Class Declaration

Here’s the declaration for com.google.common.primitives.Bytesclass:

Methods

Sr.No

Method & Description

1

static List<Byte> asList(byte... backingArray)

Returns a fixed-size list backed by the specified array, similar to Arrays.asList(Object[]).

2

static byte[] concat(byte[]... arrays)

Returns the values from each provided array combined into a single array.

3

static boolean contains(byte[] array, byte target)

Returns true if the target is present as an element anywhere in array.

4

static byte[] ensureCapacity(byte[] array, int minLength, int padding)

Returns an array containing the same values as the array, but guaranteed to be of a specified minimum length.

5

static int hashCode(byte value)

Returns a hash code for value; equal to the result of invoking ((Byte) value).hashCode().

6

static int indexOf(byte[] array, byte target)

Returns the index of the first appearance of the value target in array.

7

static int indexOf(byte[] array, byte[] target)

Returns the start position of the first occurrence of the specified target within the array, or -1 if there is no such occurrence.

8

static int lastIndexOf(byte[] array, byte target)

Returns the index of the last appearance of the value target in array.

9

static byte[] toArray(Collection<? extends Number> collection)

Returns an array containing each value of collection, converted to a byte value in the manner of Number.byteValue().

Methods Inherited

This class inherits methods from the following class:

  • java.lang.Object

Example of Bytes Class

Create the following java program using any editor of your choice in say C:/> Guava.

GuavaTester.java

Verify the Result

Compile the class using javac compiler as follows:

Now run the GuavaTester to see the result.

See the result.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Guava Topics