ByteBuffer and Byte Array
问题 Problem I need to convert two ints and a string of variable length to bytes. What I did I converted each data type into a byte array and then added them into a byte buffer. Of which right after that I will copy that buffer to one byte array, as shown below. byte[] nameByteArray = cityName.getBytes(); byte[] xByteArray = ByteBuffer.allocate(4).putInt(x).array(); byte[] yByteArray = ByteBuffer.allocate(4).putInt(y).array(); ByteBuffer byteBuffer = ByteBuffer.allocate(nameByteArray.length +