Java Convert via ByteBuffer longToByteArray(long l)

Here you can find the source of longToByteArray(long l)

Description

Transform a long into a byte array

License

Open Source License

Parameter

Parameter Description
l The long value

Return

A byte array

Declaration

public static byte[] longToByteArray(long l) 

Method Source Code


//package com.java2s;
import java.nio.ByteBuffer;

public class Main {
    /**//from  www.  j  a  va  2s .  c  o m
     * Transform a long into a byte array
     * @param l The long value
     * @return A byte array
     */
    public static byte[] longToByteArray(long l) {
        ByteBuffer buffer = ByteBuffer.allocate(8);
        buffer.putLong(l);
        return buffer.array();
    }
}

Related

  1. intToBytesWithLen(int x, int len)
  2. long2bytes(long num)
  3. longFromBytes(byte[] array)
  4. longFromBytes(byte[] value)
  5. longTo4ByteArray(long n)
  6. longToByteArray(long value)
  7. longToByteArray(long value)
  8. longToByteArray(long[] array)
  9. longToBytes(final long value)