Difficulty with the use of wrapper classes here. I want to create a List full of integers that comes from an int[]. Please help me understand how to give Arrays.asList(Object[])this array: private int[] xxx = {23, 45, 89, 54, 21}; I have tried String[] = no problem... I have tried Integer[] = problem... TIA
Paul Stevens
Ranch Hand
Joined: May 17, 2001
Posts: 2823
posted
0
Not sure exactly what your problem is. Are you trying to put the contents of the int array into an Integer array? If so, each element of the int array will need to be put into an Integer. int[] a = {1,2,3,4}; Integer[] b = new Integer[a.length]; for (int i = 0; i < a.length; i++) { b[i] = new Integer(a[i]); }
Kai Middleton
Greenhorn
Joined: Jul 27, 2001
Posts: 12
posted
0
I've had a similar though not identical situation. I'd like to do something like this: ArrayList a = Collections.createList({1, 2, 3, 4}); That way I could write quickie test programs. Is there such a method?
<I>Kai M.</I>
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
10
posted
0
It seems that you would need to create an Integer[] array from your int[] array before you can pass it as an Object[] array.
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
manahei
Greenhorn
Joined: Jul 16, 2001
Posts: 3
posted
0
Paul nailed it. Thanks
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.