File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Spring in Action this week in the Spring 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to add an array to an ArrayList