Java Convert via ByteBuffer toShortArray(byte[] arr)

Here you can find the source of toShortArray(byte[] arr)

Description

Convert byte array to short array

License

Open Source License

Parameter

Parameter Description
arr Array of bytes

Return

Array of shorts

Declaration

public static short[] toShortArray(byte[] arr) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class Main {
    /**/*w w w.ja  va  2  s  .  c o  m*/
     * Convert byte array to short array
     * @param arr Array of bytes
     * @return Array of shorts
     */
    public static short[] toShortArray(byte[] arr) {
        short[] shortBlocks = new short[arr.length / 2];
        ByteBuffer.wrap(arr).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(shortBlocks);
        return shortBlocks;
    }
}

Related

  1. toMappedBuffer(File file, long start, long end)
  2. toMsftBinary(UUID uuid)
  3. toShort(byte firstByte, byte secondByte)
  4. toShort(byte[] bytes, int index)
  5. toShort(final byte byteValue, final ByteOrder byteOrder)
  6. toShortArray(final byte[] byteArray)
  7. toSimpleList(List attrValues)
  8. toString(byte[] buf, int arrayOffset, int origLimit, StringBuilder sb)
  9. toString(byte[] value, int offset, int length, String encoding)