wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes how to add an array  to an ArrayList 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "how to add an array  to an ArrayList" Watch "how to add an array  to an ArrayList" New topic
Author

how to add an array to an ArrayList

suja changanam
Greenhorn

Joined: Sep 27, 2007
Posts: 12
This is my code :

import java.util.ArrayList;
class collection<T>
{
T[] ob;
collection(T[] ob)

{
this.ob=ob;
}

public static void main(String args[])
{
ArrayList<Integer> list=new ArrayList<Integer>();
Integer [] i={2,4,5,67,8};
collection<Integer> i1=new collection<Integer>(i);
//list.add(i);

}
}
ahmed yehia
Ranch Hand

Joined: Apr 22, 2006
Posts: 424
You can use asList(T []) in the Arrays class, but this method returns List.
try this code:
Tony Smith
Ranch Hand

Joined: Jul 07, 2007
Posts: 229
I have not tested this but try:
ArrayList<Integer[]> list=new ArrayList<Integer[]>();
suja changanam
Greenhorn

Joined: Sep 27, 2007
Posts: 12
Thank you to Ahmed Yehia &Tony smith,it's working well
suja
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to add an array to an ArrayList
 
Similar Threads
Autoboxing - Good or Bad
Type argument inference in Generics
Question about Generics in Arrays
Generic methods
[newbie] Vector of arrays...how to add them