Results 1 to 6 of 6
  1. #1
    silverglade is offline Senior Member
    Join Date
    Feb 2009
    Posts
    182
    Rep Power
    6

    Default what does "get(0);" do please?

    Hi I am having problems understanding the following code any help greatly appreciated as I could not find the answer anywhere. Here is the code


    Java Code:
    ArrayList<Dog> myDogArrayList = new ArrayList<Dog>();
    Dog aDog = new Dog();
    myDogArrayList.add(aDog);
    Dog d = myDogArrayList.[B]get(0);[/B]
    I do not understand the "get(0);" please if anyone can explain that please Thank you. Derek:D

  2. #2
    f1gh is offline Member
    Join Date
    Nov 2010
    Posts
    46
    Rep Power
    0

    Default

    an arraylist is basically an index based collection and get is a method that allows you to get the specified index. since index's start at 0, get(0) will get the first element that is added to the particular arraylist.

    In case of your code it will return the reference to your Dog object called aDog.

  3. #3
    silverglade is offline Senior Member
    Join Date
    Feb 2009
    Posts
    182
    Rep Power
    6

    Default

    THANK YOU SO MUCH F1GH!! THAT WAS DRIVING ME TOTALLY NUTS. So thank you. I have another question that I will post on here, but it is so confusing I'm not even sure how to state the question yet. LOL. thank you for keeping me sane. Derek

  4. #4
    f1gh is offline Member
    Join Date
    Nov 2010
    Posts
    46
    Rep Power
    0

    Default

    no problem. glad to help.

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    One thing you may find incredibly beneficial is a bookmark to the java APIs. Alternatively you can search the API with a class name. To find the array list API you would google this term "arraylist java 6". It should be the first hit.

    Once at the API you can find a quick description of how the class works with some examples. You will also find a list of all the classes constants(if any), a short description of all the methods, and a more thorough description near the bottom. The api's are invaluable.

  6. #6
    silverglade is offline Senior Member
    Join Date
    Feb 2009
    Posts
    182
    Rep Power
    6

    Default

    yes thanks very much. I have the link written in my book now, and all over my hard saved. That is basically the whole toolbox of java. Great thank you. Derek

Similar Threads

  1. Setting up "Stop" and "Resume" with SourceDataLine
    By davisburns in forum Advanced Java
    Replies: 0
    Last Post: 03-08-2011, 03:05 PM
  2. Replies: 3
    Last Post: 10-12-2010, 04:21 PM
  3. Replies: 1
    Last Post: 01-21-2010, 09:20 AM
  4. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 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
  •