Results 1 to 2 of 2
  1. #1
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Question add method in arrays

    I am having problem making a Grocery List.

    At First I wanted to use an Array, though I ran into problem with the addd and remove command so I decided to use the Vector class.

    I would love to use the array, if any one has an algorithm that works just like the one in the vector class that would be useful. Or Better yet tell me why this alogrith has a fault...



    Java Code:
    static int index;
    GroceryItemOrder[] items; //Array of the item Object 
    
    //The add method
    public void add(GroceryItemOrder item)
    {
    //if there are no items already
        if(index ==0)
    {
       items[index]= item;
    }else // if there are, save in next slot
    {
      items[index + 1] = item;
    }
    
    }
    
    //for the remove method I just decided to set the value to be removed to null.

  2. #2
    MuslimCoder is offline Senior Member
    Join Date
    Jan 2009
    Posts
    119
    Rep Power
    0

    Default

    I got the problem.. it works fine now though i am having a bit of a problem again..

Similar Threads

  1. Replies: 2
    Last Post: 03-26-2010, 06:12 PM
  2. Help!! With arrays
    By ookie833 in forum New To Java
    Replies: 8
    Last Post: 12-14-2008, 01:57 AM
  3. 2D Arrays
    By Major90 in forum New To Java
    Replies: 6
    Last Post: 11-06-2008, 03:08 PM
  4. Replies: 29
    Last Post: 09-25-2008, 08:55 PM
  5. cannot call private method from static method
    By jon80 in forum New To Java
    Replies: 3
    Last Post: 05-07-2008, 09:37 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
  •