Problem: Convert Object array to Primitive array vice versa.
Solution: ArrayUtils in apache commons lang can be used to do the same.
package com.lac; import org.apache.commons.lang.ArrayUtils; public class Conversion { public static void main(String[] args) { int i[] = new int[] { 1, 2, 3, 4 }; // Convert Primitive int array to Object Integer Array Integer obj[] = ArrayUtils.toObject(i); // Convert Object array to Primitive array i = ArrayUtils.toPrimitive(obj); } }
No comments:
Post a Comment