File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieving the first item in list

 
Douglas Wolfinger
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Doug Wolfinger
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've solved it. I should have had the for loop counting down

Thanks!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic