to Integer Array - Java java.lang

Java examples for java.lang:int Array

Description

to Integer Array

Demo Code


import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class Main{
    public static void main(String[] argv) throws Exception{
        int[] values = new int[]{34,35,36,37,37,37,67,68,69};
        System.out.println(java.util.Arrays.toString(toIntegerArray(values)));
    }/*from   w ww .  j  av a 2 s .  c o m*/
    
    public static Integer[] toIntegerArray(int[] values) {
        if (values == null) {
            return null;
        }
        Integer[] result = new Integer[values.length];
        for (int i = 0; i < values.length; i++) {
            result[i] = new Integer(values[i]);
        }
        return result;
    }
    
    public static String toString(Object[] aryObjects) {
        if (aryObjects == null) {
            return "null";
        }
        int maxIndex = aryObjects.length - 1;
        if (maxIndex < 0) {
            return "[]";
        }
        StringBuilder sb = new StringBuilder();
        sb.append(maxIndex + 1).append(" elements: [");
        sb.append(EnvConst.NEWLINE);
        for (int i = 0; i < maxIndex; i++) {
            sb.append(i).append(":").append(aryObjects[i]);
            sb.append(EnvConst.NEWLINE);
        }
        sb.append(maxIndex).append(":").append(aryObjects[maxIndex]);
        sb.append("]");
        return sb.toString();
    }
    
    public static String toString(int[] values) {
        return toString(toIntegerArray(values));
    }
    
    public static String toString(boolean[] values) {
        return toString(toBooleanArray(values));
    }
    
    public static Object[] toBooleanArray(boolean[] values) {
        if (values == null) {
            return null;
        }
        Boolean[] result = new Boolean[values.length];
        for (int i = 0; i < result.length; i++) {
            result[i] = new Boolean(values[i]);
        }
        return result;
    }
}

Related Tutorials