Java Array Create newArray(Object obj, int size)

Here you can find the source of newArray(Object obj, int size)

Description

new Array

License

Open Source License

Declaration

public static Object newArray(Object obj, int size) 

Method Source Code

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

public class Main {
    public static Object newArray(Object obj, int size) {
        if (obj.getClass().equals(Integer.class)) {
            return new int[size];
        }/*  w w  w . j a  v  a 2  s . c o  m*/
        if (obj.getClass().getName().contains("I")) {
            return new int[size];
        }
        if (obj.getClass().getName().contains("F")) {
            return new float[size];
        }
        if (obj.getClass().getName().contains("C")) {
            return new char[size];
        }
        if (obj.getClass().getName().contains("J")) {
            return new long[size];
        }
        if (obj.getClass().getName().contains("S")) {
            return new short[size];
        }
        if (obj.getClass().getName().contains("B")) { // byte
            return new byte[size];
        }
        if (obj.getClass().getName().contains("Z")) { // boolean
            return new boolean[size];
        }
        if (obj.getClass().getName().contains("D")) {
            return new double[size];
        }
        return null; // UNKNOWN TYPE.
    }
}

Related

  1. ArrayToArray(Integer obj, Integer[] objArray)
  2. ArrayToObject(byte[] values)
  3. newArray()
  4. newArray(Class elementType, int length)
  5. newArray(int length, double start, double increment)
  6. newArray(Object src, int len)
  7. newArray(String... args)
  8. toArray(String source, String delimiter)
  9. toArray(String str)