• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to add an array to an ArrayList

 
suja changanam
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use asList(T []) in the Arrays class, but this method returns List.
try this code:
 
Tony Smith
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not tested this but try:
ArrayList<Integer[]> list=new ArrayList<Integer[]>();
 
suja changanam
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you to Ahmed Yehia &Tony smith,it's working well
suja
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic