This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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
 
 
subject: how to add an array to an ArrayList
 
Similar Threads
Type argument inference in Generics
Question about Generics in Arrays
Generic methods
Autoboxing - Good or Bad
[newbie] Vector of arrays...how to add them