Q:

Convert float[] to byte[] to float[] again

So what I'm trying to do here is get a float[], convert it to byte[], send it through the network as a datagram packet and then convert it back to a byte[] at the receiving terminal.
Now I know I can convert float[] to byte[] by using the getBytes[] method. But I don't know how to reverse the conversion.

A:

I think you want to make use of the ByteBuffer class, which has putFloat and getFloat methods.

A:

Another way... use ByteArrayOutputStream/DataOutputStream for output
float fArr[] = ...;
ByteArrayOutputStream bas = new ByteArrayOutputStream();
DataOutputStream ds = new DataOutputStream(bas);
for (float f : fArr) 
    ds.writeFloat(f);
byte[] bytes = bas.toByteArray();

Use ByteArrayInputStream/DataInputStream for input
byte[] buffer = ...;
ByteArrayInputStream bas = new ByteArrayInputStream(buffer);
DataInputStream ds = new DataInputStream(bas);
float[] fArr = new float[buffer.length / 4];  // 4 bytes per float
for (int i = 0; i < fArr.length; i++)
{
    fArr[i] = ds.readFloat();
}

A:

Use Float.floatToIntBits() to extract the bit-value of the float as an integer, then use BigInteger.toByteArray() to make a byte[].  This can be reversed using the BigInteger constructor that takes a byte[] argument, and then Float.intBitsToFloat().

