Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: ArrayLists - Getting index of parameters of objects of ArrayLists.

  1. #1
    Member
    Join Date
    Oct 2011
    Posts
    46
    My Mood
    Asleep
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default ArrayLists - Getting index of parameters of objects of ArrayLists.

    I have this borderline difficult HW assignment that introduced ArrayLists about a lesson back from the one I am on now. Currently I am having difficulty doing something (and wording) to make the script work right. Lets say I have the following (example script):

    ArrayList<ShapesV4> shapes = new ArrayList<ShapesV4>();
            shapes.add(new ShapesV4(10, 5));
            shapes.add(new ShapesV4(7, 1));
            shapes.add(new ShapesV4(5, 2));


    Except mine has one int and several Boolean statements as the parameters of the "new shapes object". I am currently trying to figure out how to get the element of the parameters of one of the shapes objects. From what I have figured out, sometihng like shapes.get(x) will only get the object and not the element of a parameter of one of those objects. I need to be able to iterate through the parameters of all those objects but I don't know how to set that up. I figured it would look something like shapes.get(0[1]) to get the number 5 of the first object. But obviously that isn't correct... What is the correct setup if someone is kind enough to answer?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: ArrayLists - Getting index of parameters of objects of ArrayLists.

    how to get the element of the parameters of one of the shapes objects.
    You could do it in two steps.
    1) get an Shapes object reference out of the ArrayList using the get method
    2) use that object reference to call a Shapes class method.

Similar Threads

  1. Creating ArrayLists
    By Khadafi in forum Java Theory & Questions
    Replies: 15
    Last Post: January 12th, 2012, 06:18 PM
  2. How to separate ArrayLists in memory?
    By wattieboi in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 22nd, 2011, 01:18 AM
  3. Sprite Animation with ArrayLists
    By FShounen in forum AWT / Java Swing
    Replies: 13
    Last Post: June 6th, 2011, 08:43 AM
  4. Quick question, arraylists
    By Intensity` in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: May 16th, 2011, 08:47 PM
  5. Transferring elements between arraylists
    By KipTheFury in forum Collections and Generics
    Replies: 6
    Last Post: August 23rd, 2010, 02:13 PM