Results 1 to 6 of 6
  1. #1
    ztomtomz is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Arraylist-Objects

    I have been given a couple of methods to complete and my arraylist is a object containing strings.

    Items is the name for the arraylist.
    itemmanager is a class.
    The hints tell me to use booleans but i can't change the class object. Also i need to complete this without using booleans.
    i thought i was getting somewhere but seem to of hit a road bump if anyone could point me in the right way or direct me to a tutorial that would be extremely helpful thank you in advance.


    Itemmanager removeItemAt(Integer index)
    {

    if (index < Items.size() && index >= 0)
    {
    Items.remove(Items.get(index));

    }
    }

  2. #2
    Jingoism is offline Member
    Join Date
    Nov 2012
    Posts
    14
    Rep Power
    0

    Default Re: Arraylist-Objects

    Quote Originally Posted by ztomtomz View Post
    I have been given a couple of methods to complete and my arraylist is a object containing strings.

    Items is the name for the arraylist.
    itemmanager is a class.
    The hints tell me to use booleans but i can't change the class object. Also i need to complete this without using booleans.
    i thought i was getting somewhere but seem to of hit a road bump if anyone could point me in the right way or direct me to a tutorial that would be extremely helpful thank you in advance.


    Itemmanager removeItemAt(Integer index)
    {

    if (index < Items.size() && index >= 0)
    {
    Items.remove(Items.get(index));

    }
    }
    So the hints tell you to use booleans, but you must complete this without using booleans? I'm confused.

    The method that you are showing:

    Java Code:
    Itemmanager removeItemAt(Integer index)
    	{
    		if (index < Items.size() && index >= 0)
    		{
    			Items.remove(Items.get(index));
    
    		}
    		return this;
    	}
    That works fine if you pass it a number to delete from the ArrayList ( I added "return this" since you are giving it an object type that it must return ).

    Might help to see the whole program in context.

  3. #3
    ztomtomz is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: Arraylist-Objects

    Sorry my fault, this doesn't work because the class of the method is in a different class so when i got to return all i get is 'change method return type to request'. request is an independent class and holds its own methods which contain information.

  4. #4
    ztomtomz is offline Member
    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Default Re: Arraylist-Objects

    Does anyone have any idea i really am stumped


    Java Code:
    Itemmanager removeItemAt(Integer index)
        {
            if (index < Items.size() && index >= 0)
            {
                Items.remove(Items.get(index));
     
            }
            return this;
        }
    this works if the object method is the same as the class that it is in but i am in a different class
    Last edited by ztomtomz; 11-17-2012 at 06:22 PM.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: Arraylist-Objects

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Arraylist-Objects

    works if the object method is the same as the class that it is
    This sentence doesn't make sense. Can you clarify?

Similar Threads

  1. Counting objects in ArrayList
    By Gunther34567 in forum Java Servlet
    Replies: 1
    Last Post: 05-17-2012, 02:01 PM
  2. Add objects to ArrayList with Polymorphism
    By africanhacker in forum New To Java
    Replies: 7
    Last Post: 06-29-2011, 02:59 PM
  3. [HELP] Removing objects from an ArrayList!
    By bpx95 in forum New To Java
    Replies: 4
    Last Post: 04-30-2011, 05:54 AM
  4. Help with objects in ArrayList
    By BiteMuncher in forum New To Java
    Replies: 7
    Last Post: 02-21-2011, 11:55 AM
  5. ArrayList with different objects? Help
    By xtrmi in forum New To Java
    Replies: 4
    Last Post: 02-27-2009, 08:51 PM

Posting Permissions

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