Convert byte array to short in Java
Description
The following code shows how to convert byte array to short.
Example
/*from w w w.j a v a2s .co m*/
import java.nio.ByteBuffer;
public class Main {
public static short convertToShort(byte[] array) {
ByteBuffer buffer = ByteBuffer.wrap(array);
return buffer.getShort();
}
public static void main(String[] argv) {
System.out.println(convertToShort(new byte[]{1,2,3,4,5,6,7,8,9,8,67}));
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »