How do I Convert Array to Collection?

Bookmark this example!  
Category: java.util, viewed: 1863 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) + ", ");
        }
    }    
}
 
 
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