Results 1 to 6 of 6
Thread: what does "get(0);" do please?
- 04-29-2011, 12:45 AM #1
Senior Member
- Join Date
- Feb 2009
- Posts
- 182
- Rep Power
- 5
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
I do not understand the "get(0);" please if anyone can explain that please Thank you. Derek:DJava Code:ArrayList<Dog> myDogArrayList = new ArrayList<Dog>(); Dog aDog = new Dog(); myDogArrayList.add(aDog); Dog d = myDogArrayList.[B]get(0);[/B]
- 04-29-2011, 12:50 AM #2
Member
- Join Date
- Nov 2010
- Posts
- 44
- Rep Power
- 0
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.
- 04-29-2011, 01:12 AM #3
Senior Member
- Join Date
- Feb 2009
- Posts
- 182
- Rep Power
- 5
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
- 04-29-2011, 01:14 AM #4
Member
- Join Date
- Nov 2010
- Posts
- 44
- Rep Power
- 0
no problem. glad to help.
- 04-29-2011, 01:18 AM #5
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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.
- 04-29-2011, 04:14 AM #6
Senior Member
- Join Date
- Feb 2009
- Posts
- 182
- Rep Power
- 5
Similar Threads
-
Setting up "Stop" and "Resume" with SourceDataLine
By davisburns in forum Advanced JavaReplies: 0Last Post: 03-08-2011, 03:05 PM -
connection = DriverManager.getConnection(DATABASE_URL,'"+userid +"','"+password+"');
By renu in forum New To JavaReplies: 3Last Post: 10-12-2010, 04:21 PM -
How to change my form design from "metal" to "nimbus" in Netbeans 6.7.1?
By mlibot in forum New To JavaReplies: 1Last Post: 01-21-2010, 09:20 AM -
MoneyOut.println("It took you (whats wrong?>",year,"<WW?) years to repay the loan")
By soc86 in forum New To JavaReplies: 2Last Post: 01-24-2009, 06:56 PM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks