Java Convert via ByteBuffer toByteArray(double[] doubleArray)

Here you can find the source of toByteArray(double[] doubleArray)

Description

to Byte Array

License

LGPL

Declaration

public static byte[] toByteArray(double[] doubleArray) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.nio.ByteBuffer;

public class Main {
    public static byte[] toByteArray(double[] doubleArray) {
        int times = Double.SIZE / Byte.SIZE;
        byte[] bytes = new byte[doubleArray.length * times];
        for (int i = 0; i < doubleArray.length; i++) {
            ByteBuffer.wrap(bytes, i * times, times).putDouble(doubleArray[i]);
        }//ww w .java2s .co m
        return bytes;
    }

    public static byte[] toByteArray(int[] intArray) {
        int times = Integer.SIZE / Byte.SIZE;
        byte[] bytes = new byte[intArray.length * times];
        for (int i = 0; i < intArray.length; i++) {
            ByteBuffer.wrap(bytes, i * times, times).putInt(intArray[i]);
        }
        return bytes;
    }
}

Related

  1. toByte(final char[] charArray)
  2. toByte(int input, int count)
  3. toByteArray(BitSet bits)
  4. toByteArray(char[] chars)
  5. toByteArray(double value)
  6. toByteArray(float[] floatArray)
  7. toByteArray(InputStream input, boolean nioCopy)
  8. toByteArray(int i)
  9. toByteArray(int integer)