permaculture playing cards*
The moose likes Beginning Java and the fly likes Retrieving the first item in list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Retrieving the first item in list" Watch "Retrieving the first item in list" New topic
Author

Retrieving the first item in list

Douglas Wolfinger
Ranch Hand

Joined: Aug 28, 2000
Posts: 57
I am using a class ListArrayBased to define the add() and get() methods. I would like to know how to retrieve the first item. The items are added from the list position of 1, and get() throws an exception if I specify get(0).
The purpose of the class is to sum the items in the list.

[ September 18, 2002: Message edited by: Douglas Wolfinger ]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Sorry can't guess the implementation of ListArrayBased.
What happens when you replace lab.add(1,...) by lab.add(0,...) where it appears.
-Barry
[ September 18, 2002: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Doug Wolfinger
Greenhorn

Joined: Jul 27, 2002
Posts: 18
Here are the get and add methods. numItems is equal to the size of the list. This is how the code is written in the text. The index has to be one less than the position. Thanks.
Doug Wolfinger
Greenhorn

Joined: Jul 27, 2002
Posts: 18
I've solved it. I should have had the for loop counting down

Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retrieving the first item in list