Possible Duplicate:
How to create ArrayList (ArrayList<T>) from array (T[]) in Java
How to implement this method:
List<Integer> toList(int[] integers) {
???
//return Arrays.asList(integers); doesn't work
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s probably a built-in method to do it somewhere* (as you note,
Arrays.asListwon’t work as it expects anInteger[]rather than anint[]).I don’t know the Java libraries well enough to tell you where that is. But writing your own is quite simple:
Obviously one downside of this is that you can’t do it generically. You’ll have to write a separate
createListmethod for each autoboxed primitive type you want.*And if there isn’t, I really wonder why not.