Here you can find the source of intsToBytes(int[] n)
public static byte[] intsToBytes(int[] n)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; import java.nio.IntBuffer; import java.util.List; public class Main { public static byte[] intsToBytes(int[] n) { byte[] bytes = new byte[n.length * (Integer.SIZE / 8)]; ByteBuffer b = ByteBuffer.wrap(bytes); b.asIntBuffer().put(n);//from ww w. j a va2s. c o m return bytes; } public static byte[] intsToBytes(List<Integer> n) { byte[] bytes = new byte[n.size() * (Integer.SIZE / 8)]; ByteBuffer b = ByteBuffer.wrap(bytes); IntBuffer ib = b.asIntBuffer(); for (int val : n) ib.put(val); return bytes; } }