How do I Convert Array to Collection?

Category: java.util, viewed: 4K time(s).
package org.kodejava.example.java.util;

import java.util.Arrays;
import java.util.List;

public class ArrayToListExample 
{
    public static void main(String[] args) 
    {
        // Creates an array of object, in this case we create an
        // Integer array.
        Integer[] numbers = {1, 1, 2, 3, 5, 8, 13, 21, 34, 55};
        
        // Convert the created array above to collection, in this
        // example we convert it to a List.
        List list = Arrays.asList(numbers);

        // We've got a list of our array here and iterate it.
        for (int i = 0; i < list.size(); i++)
        {
            System.out.print(list.get(i) + ", ");
        }
    }    
}