Results 1 to 5 of 5
Thread: ArrayList problem.
- 10-15-2010, 10:17 AM #1
Member
- Join Date
- May 2010
- Posts
- 34
- Rep Power
- 0
ArrayList problem.
I have a Box class, Bag class and a Apple class .
the Bag class contains an ArrayList.
BAG CLASS
BOX CLASSJava Code:ArrayList<Apple> apples = new ArrayList<Apple>(); public int getSize() { int i = apples.getSize(); return i; }
I want to getSize() the number of apples by asking the bag class.Java Code:Bag.apples.getSize();
How do i bring the array over to box class to check the getSize() method? Because I know I can't use 2 calls.
If I Bag.getSize, its asking the whole class (non static...) but I also don't want to create a new array to get back 0.
- 10-15-2010, 10:39 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
use an instance of the Bag class rather than "Bag" in that call and remove ".apples" from that call.
- 10-15-2010, 10:51 AM #3
Member
- Join Date
- May 2010
- Posts
- 34
- Rep Power
- 0
So if I do that, b can identify the Arraylist automatically?Java Code:Bag b; b.getSize();
Thanks, Its complied.
- 10-15-2010, 10:57 AM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Bag has a "getSize()" method (according to that code), and that method calls "size()" on the instance variable, so, yeah. I mean, that's what all that is for, after all.
- 10-15-2010, 11:22 AM #5
Member
- Join Date
- May 2010
- Posts
- 34
- Rep Power
- 0
Similar Threads
-
Arraylist problem
By keo in forum New To JavaReplies: 3Last Post: 05-28-2010, 10:38 AM -
ArrayList problem
By brian.baert in forum New To JavaReplies: 8Last Post: 03-06-2010, 01:49 PM -
Hey! ArrayList problem here
By Samgetsmoney in forum New To JavaReplies: 31Last Post: 02-20-2009, 12:39 AM -
ArrayList problem with images
By Cymro in forum New To JavaReplies: 2Last Post: 02-05-2008, 06:22 PM -
ArrayList problem
By khamuruddeen in forum New To JavaReplies: 7Last Post: 12-22-2007, 05:46 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks