Java Primitive Type Create toPrimitive(Character[] in)

Here you can find the source of toPrimitive(Character[] in)

Description

to Primitive

License

Open Source License

Declaration

public static char[] toPrimitive(Character[] in) 

Method Source Code

//package com.java2s;

public class Main {
    public static long[] toPrimitive(Long[] in) {
        return toPrimitive(in, 0L);
    }//w  ww  .ja  v  a  2  s.  c om

    public static int[] toPrimitive(Integer[] in) {
        return toPrimitive(in, 0);
    }

    public static short[] toPrimitive(Short[] in) {
        return toPrimitive(in, (short) 0);
    }

    public static char[] toPrimitive(Character[] in) {
        return toPrimitive(in, (char) 0);
    }

    public static double[] toPrimitive(Double[] in) {
        return toPrimitive(in, 0.0);
    }

    public static long[] toPrimitive(Long[] in, long valueForNull) {
        if (in == null)
            return null;
        final long[] out = new long[in.length];
        for (int i = 0; i < in.length; i++) {
            Long b = in[i];
            out[i] = (b == null ? valueForNull : b);
        }
        return out;
    }

    public static int[] toPrimitive(Integer[] in, int valueForNull) {
        if (in == null)
            return null;
        final int[] out = new int[in.length];
        for (int i = 0; i < in.length; i++) {
            Integer b = in[i];
            out[i] = (b == null ? valueForNull : b);
        }
        return out;
    }

    public static short[] toPrimitive(Short[] in, short valueForNull) {
        if (in == null)
            return null;
        final short[] out = new short[in.length];
        for (int i = 0; i < in.length; i++) {
            Short b = in[i];
            out[i] = (b == null ? valueForNull : b);
        }
        return out;
    }

    public static char[] toPrimitive(Character[] in, char valueForNull) {
        if (in == null)
            return null;
        final char[] out = new char[in.length];
        for (int i = 0; i < in.length; i++) {
            Character b = in[i];
            out[i] = (b == null ? valueForNull : b);
        }
        return out;
    }

    public static double[] toPrimitive(Double[] in, double valueForNull) {
        if (in == null)
            return null;
        final double[] out = new double[in.length];
        for (int i = 0; i < in.length; i++) {
            Double b = in[i];
            out[i] = (b == null ? valueForNull : b);
        }
        return out;
    }
}

Related

  1. toPrimitive(Boolean[] array)
  2. toPrimitive(Byte[] byteArray)
  3. toPrimitive(Byte[] bytes)
  4. toPrimitive(Byte[] objectArray)
  5. toPrimitive(Character value)
  6. toPrimitive(Class aClass)
  7. toPrimitive(Class clazz)
  8. toPrimitive(Double[] array)
  9. toPrimitive(Double[] array)