wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Passing 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 » Java » Beginning Java
Bookmark "Passing ArrayList" Watch "Passing ArrayList" New topic
Author

Passing ArrayList

R Jarman
Greenhorn

Joined: Feb 08, 2005
Posts: 27
I have a class with a private variable

privateArrayList<Bid>bids = new ArrayList<Bid>();

I'm setting this variable in the constructor for the class, so the constructor looks like this.

public Pruning ( ArrayList _bids)
{
bids.addAll ( _bids );
}

I don't think I'm doing something right. How do I tell the constructor the type of the argument. I tried

public Pruning ( ArrayList<Bid> _bids)

like I did in the variable declaration but it won't compile. What am I missing?
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
I tried

public Pruning ( ArrayList<Bid> _bids)

like I did in the variable declaration but it won't compile. What am I missing?


That looks okay. What type of error message did the compiler give?


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Robert Hill
Ranch Hand

Joined: Feb 24, 2006
Posts: 94
How are you invoking the constructor?

ie Pruning p = new Pruning(bids)

Why do you instantiating an ArrayList as a private member and then passing another one in the constructor. Is that what you want?

This might be what you want:

private ArrayList<Bid> bids;

public Pruning ( ArrayList<Bid> _bids)
{
bids = _bids;
}


addAll() appends the passed list to the private one, but the private list has no elements yet.
 
Don't get me started about those stupid light bulbs.
 
subject: Passing ArrayList
 
Similar Threads
Cascade-save HELP !!!!
filing an array with the output from a method
Iterating through unknown enum type variable
Three Dimensional ArrayList?
Copying objects to arraylists