Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Retrieving the first item in list

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've solved it. I should have had the for loop counting down

Thanks!
 
reply
    Bookmark Topic Watch Topic
  • New Topic