Results 1 to 4 of 4
  1. #1
    keo
    keo is offline Member
    Join Date
    May 2010
    Posts
    34
    Rep Power
    0

    Default Arraylist problem

    Hello, I'm not sure what I need to do to add an object to an array on another class and then check how many of objectA is inside objectB.

    So I've got two classes, for example; apple class and basket class.
    I need to add more than one new apple(s) to the basket using methods.

    So in the basket class I will attempt to:

    Java Code:
                   [I]INSTANCE VARIABLES[/I]
    private Apple[] apple = {}; //create Array?
    
                   [I]METHODS[/I]
    public addApple(String appleName)
    {
       apple[] = new appleName; //add new apple to next avaliable array spot.
    }
    
    public int getNumberOfApples()
    {
       return length.apples;
    }
    I am assuming that the body of the methods are incorrect, and may be missing other things. Both methods don't seem to currently work, and I'm new to java. Help is appreciated! Thanks.

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    keo
    keo is offline Member
    Join Date
    May 2010
    Posts
    34
    Rep Power
    0

    Default

    Hi, thanks for the link. I've read it, but I can't find what I need to know.

    The article tells you how to insert the number of "elements" when you know how many you want, but in my case, I don't want to limit how many there are and to start with none,

    And there is nothing about how to add another object to the end of the arraylist.

    Thanks,

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

Similar Threads

  1. ArrayList problem
    By brian.baert in forum New To Java
    Replies: 8
    Last Post: 03-06-2010, 01:49 PM
  2. Problem with constructing an ArrayList
    By Diplo in forum New To Java
    Replies: 5
    Last Post: 12-07-2009, 03:52 PM
  3. Hey! ArrayList problem here
    By Samgetsmoney in forum New To Java
    Replies: 31
    Last Post: 02-20-2009, 12:39 AM
  4. ArrayList problem with images
    By Cymro in forum New To Java
    Replies: 2
    Last Post: 02-05-2008, 06:22 PM
  5. ArrayList problem
    By khamuruddeen in forum New To Java
    Replies: 7
    Last Post: 12-22-2007, 05:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •