The following example shows converting an Integer to Byte array.
Since a Java Integer occupies 4 bytes allocate a ByteBuffer of capacity 4
and write the Integer to ByteBuffer. It updates the ByteBuffer with
4 bytes representing the Integer. Finally convert the ByteBuffer to byte array.
java.nio.ByteBuffer
public static ByteBuffer allocate(int capacity) Allocates a new byte buffer of given capacity.
public ByteBuffer putInt(int value) Writes four bytes containing the given int value to this ByteBuffer.
public final byte[] array() Returns the ByteBuffer as byte array.