• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Adding a List using hasnext(),next() (user defined)

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


output: error
array index exception
return object= null
array index exception
return object= null
array index exception
return object= null
array index exception
return object= null
array index exception
return object= null
array index exception
return object= null
array index exception
return object= null
array index exception
return object= null
array index exception
return object= null
array index exception
return object= null
array index exception
return object= null

may i know where i went wrong?

Thanks
samura
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in hasNext :


This is always going to be true, isn't it ?

In next(), you never increase the current index.


I'm not sending the code, but just giving you some hints :
1. in hasNext, use the index to check whether it has reached the size of the array, or to check whether the current item is null
2. in next, increase the index
reply
    Bookmark Topic Watch Topic
  • New Topic