提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
方法将int的数组集合转换为Integer的数组集合。
/**来自 NowJava.com**/ //package com.book2s; public class Main { public static void main(String[] argv) { Object objArray = "book2s.com"; System.out.println(java.util.Arrays.toString(toObject(objArray))); } /** * Method to convert a Array Collection of int to a Array Collection of Integer. * @param <T> the generic variable. * @param objArray the Array Collection of int. * @return Array Collection of Integer. */ @SuppressWarnings("unchecked") public static <T> T[] toObject(Object... objArray) { //return org.apache.commons.lang3.ArrayUtils.toObject(intArray); if (objArray == null) return null; else if (objArray[0].getClass() == int.class) { if (objArray.length == 0) return (T[]) new Integer[0]; final Integer[] result = new Integer[objArray.length];//时 代 J a v a for (