Java Array Truncate truncate(short[] value, int maxSize)

Here you can find the source of truncate(short[] value, int maxSize)

Description

Truncate an array of shorts to a specified size

License

Open Source License

Parameter

Parameter Description
value a parameter
size a parameter

Return

the truncated array of shorts

Declaration

public static short[] truncate(short[] value, int maxSize) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from   ww  w.jav  a  2 s .c  om*/
     * Truncate an array of shorts to a specified size
     * 
     * @param value
     * @param size
     * @return the truncated array of shorts
     */
    public static short[] truncate(short[] value, int maxSize) {
        int actualSize = maxSize;
        if (actualSize > value.length) {
            actualSize = value.length;
        }
        short[] returnValue = new short[actualSize];
        for (int i = 0; i < actualSize; i++) {
            returnValue[i] = value[i];
        }
        return returnValue;
    }
}

Related

  1. truncate(byte[] element, int length)
  2. truncate(byte[] nextPartBytes, int partSize)
  3. truncate(final byte[] arr, final int len)
  4. truncate(int[] array, int maxLen)
  5. truncate(int[] values, int value)
  6. truncateAndConvertToInt(long[] longArray)
  7. truncateBytes(byte[] inputBytes)
  8. truncateByteSegment(byte[] byteSegment, int toSize)
  9. truncateData(byte[] data, int numOfBytes)