Java Convert via ByteBuffer toByteArray(int[] intArray)

Here you can find the source of toByteArray(int[] intArray)

Description

Returns a new byte array using data from the given integer array.

License

Open Source License

Declaration

public static byte[] toByteArray(int[] intArray) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

public class Main {
    /**//from w  w w  . java  2s  .co m
     * Returns a new byte array using data from the given integer array.
     */
    public static byte[] toByteArray(int[] intArray) {
        ByteBuffer byteBuffer = ByteBuffer.allocate(intArray.length * 4);
        byteBuffer.asIntBuffer().put(intArray);
        return byteBuffer.array();
    }
}

Related

  1. toByteArray(int i)
  2. toByteArray(int integer)
  3. toByteArray(int value)
  4. toByteArray(int value)
  5. toByteArray(int[] data, boolean bigEndian)
  6. toByteArray(long[] data)
  7. ToByteArray(long[] data)
  8. toByteArray(ReadableByteChannel channel)
  9. toByteArray(String bits)