How do I convert array of primitives into array of objects?

Bookmark this example!  
Category: Commons Lang, viewed: 1547 time(s).
 
package org.kodejava.examples.commons.lang;
 
import org.apache.commons.lang.ArrayUtils;
 
public class ArrayUtilsExample {
    public static void main(String[] args) {
        int numbers[] = {1, 2, 3, 4, 5};
        boolean bools[] = {true, false, false, true};
        float decimals[] = {10.1f, 3.14f, 2.17f};
 
        // To convert from primitive arrays into object 
        // type arrays we can user Apache Commons Lang 
        // library. The commons lang provides an ArrayUtils 
        // class that did this conversion. To convert the 
        // other way just use the toPrimitive method.
 
        Integer numbersObj[] = 
            ArrayUtils.toObject(numbers);
        Boolean boolsObj[] = 
            ArrayUtils.toObject(bools);
        Float decimalsObj[] = 
            ArrayUtils.toObject(decimals);               
    }
}
 
 
Can't find what you are looking for? Join our FORUMS and ask some questions!

Most Viewed Examples

Latest Code Examples

100 Top & Latest


Locations of visitors to this page
eXTReMe Tracker
visitor stats
Get Chitika Premium