Java Short Number Array Create toShorts(Short[] values)

Here you can find the source of toShorts(Short[] values)

Description

to Shorts

License

Open Source License

Declaration

public static short[] toShorts(Short[] values) 

Method Source Code

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

public class Main {
    public static final short DEFAULT_SHORT = 0;

    public static short[] toShorts(Short[] values) {
        return toShorts(values, DEFAULT_SHORT);
    }/* w  ww . jav  a 2  s . c o m*/

    public static short[] toShorts(Short[] values, int defaultValue) {
        short[] results = new short[0];
        if (values != null) {
            results = new short[values.length];
            for (int i = 0; i < results.length; i++) {
                Short element = values[i];
                try {
                    results[i] = (element != null ? element.shortValue()
                            : (short) defaultValue);
                } catch (Exception ex) {
                    // ex.printStackTrace();
                }
            }
        }
        return results;
    }

    public static Short[] toShorts(short[] values) {
        return toShorts(values, DEFAULT_SHORT);
    }

    public static Short[] toShorts(short[] values, int defaultValue) {
        Short[] results = new Short[0];
        if (values != null) {
            results = new Short[values.length];
            for (int i = 0; i < results.length; i++) {
                short element = values[i];
                try {
                    results[i] = new Short(element);
                } catch (Exception ex) {
                    results[i] = (short) defaultValue;
                    // ex.printStackTrace();
                }
            }
        }
        return results;
    }
}

Related

  1. toShortArray(boolean[] array)
  2. toShorts(byte[] array, int offset, int length)
  3. toShorts(byte[] bytes)
  4. toShorts(byte[] readBuffer, int o, int l)
  5. toShorts(byte[] value, int offset, int num)