Java Array From toArray(int[] intArray)

Here you can find the source of toArray(int[] intArray)

Description

to Array

License

Open Source License

Declaration

public static Object[] toArray(int[] intArray) 

Method Source Code

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

public class Main {
    public static int[] toArray(Object[] objArray) {
        if (objArray == null)
            return null;
        int[] intArray = new int[objArray.length];
        for (int i = 0; i < objArray.length; i++)
            if (objArray[i] == null)
                intArray[i] = 0;//from   w  ww.  j a v a 2 s . c  o m
            else if (objArray[i] instanceof Number)
                intArray[i] = ((Number) objArray[i]).intValue();
            else
                intArray[i] = parseInt(objArray[i].toString());
        return intArray;
    }

    public static Object[] toArray(int[] intArray) {
        if (intArray == null)
            return null;
        Integer[] objArray = new Integer[intArray.length];
        for (int i = 0; i < intArray.length; i++)
            objArray[i] = new Integer(intArray[i]);
        return objArray;
    }

    public static int parseInt(String str) {
        try {
            if (str == null)
                return 0;
            str = str.trim();
            if (str.startsWith("+"))
                str = str.substring(1);
            int o = str.indexOf('.');
            if (o >= 0)
                str = str.substring(0, o);
            return Integer.parseInt(str);
        } catch (NumberFormatException e) {
            return 0;
        }
    }
}

Related

  1. toArray(float[] floatArray)
  2. toArray(int arg1)
  3. toArray(int time)
  4. toArray(int value)
  5. toArray(int value, byte b[], int offset)
  6. toArray(Iterable itr)
  7. toArray(long l, byte[] b, int offset)
  8. toArray(long value, byte[] dest, int offset, int length)
  9. toArray(Object a)