File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Wrapper Classes for Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Wrapper Classes for Arrays" Watch "Wrapper Classes for Arrays" New topic
Author

Wrapper Classes for Arrays

manahei
Greenhorn

Joined: Jul 16, 2001
Posts: 3
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
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
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: 9044
    
  10
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
Paul nailed it.
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wrapper Classes for Arrays
 
Similar Threads
small swapping problem please please reply!!!!!
Few Interview questions I was not sure of
conversion from Integer.MAX_VALUE to short
Object[] and Object
Why This compile error?