Java Array Capacity reduceCapacity(Object[] arrays)

Here you can find the source of reduceCapacity(Object[] arrays)

Description

reduce Capacity

License

Open Source License

Declaration

public static Object[] reduceCapacity(Object[] arrays) 

Method Source Code


//package com.java2s;
import java.util.Arrays;

public class Main {

    public static Object[] reduceCapacity(Object[] arrays) {
        if (arrays == null) {
            return null;
        }/*from w w  w.j a  va2  s. c  o  m*/
        int lastIndex = arrays.length - 1;
        int length = arrays.length;
        for (int i = lastIndex; i >= 0; i--) {
            if (arrays[i] == null) {
                length--;
            } else {
                break;
            }
        }
        if (length <= 0) {
            return null;
        }
        return Arrays.copyOf(arrays, length);
    }
}

Related

  1. ensureCapacity(byte array[], int capacity)
  2. ensureCapacity(byte[] bytes, int capacity)
  3. ensureCapacity(final double[] array, final int minCapacity)
  4. ensureCapacity(final T[] oldElements, final int requiredLength)