KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have seen the question: Create ArrayList from array However when I try that solution with following code, it doesn't quite work in all the cases: import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; public class ToArrayList { public static void main(String[] args) { // this works String[] elements = new String[] { "Ryan", "Julie", "Bob" }; List<String> list = new ArrayList<String>(Arrays.asList(elements)); System.out.println(list); // this works List<Integer> intList = null; intList = Arrays.asList(3, 5); System.out.println(intList); int[] intArray = new int[] { 0, 1 }; // this doesn't work! intList = new ArrayList<Integer>(Arrays.asList(intArray)); System.out.println(intList); } } What am I doing wrong here? Shouldn't the code intList = new ArrayList<Integer>(Arrays.asList(intArray)); compile just fine?
Tags (comma-separated)
Save Edits
Cancel