Build an ArrayList of Integer from and array of int. - Java Collection Framework

Java examples for Collection Framework:Array Element

Description

Build an ArrayList of Integer from and array of int.

Demo Code


//package com.java2s;
import java.util.ArrayList;

public class Main {
    public static void main(String[] argv) throws Exception {
        int[] list = new int[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };
        System.out.println(buildArray(list));
    }/*w w  w.  j  a va  2 s .  c om*/

    /** 
     *  Build an ArrayList of Integer from and array of int.
     */
    public static ArrayList buildArray(int[] list) {
        ArrayList nlist = new ArrayList(list.length);
        for (int i = 0; i < list.length; i++) {
            Integer val = new Integer(list[i]);
            nlist.add(val);
        }
        return (nlist);
    }
}

Related Tutorials