Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

AddAfter method

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need help figuring out how to add an element after an existing element in an array. The isCurrent boolean checks to see if there is a current element. I almost have it. I need someone to show me what im missing. Thanks,

[ October 03, 2003: Message edited by: Jere Johnson ]
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Jere -
I don't know what problem the code is giving you, but I would recommend checking for the end of the array to avoid the ArrayIndexOutOfBounds exception.
Also, I'm assuming "manyItems" is your element count?
I also see a mismatched number of curly braces. The method addAfter() is not closed.
Maybe if you provide a little more context, like the class this method belongs to and its method signatures, I could be of further help.
 
Jeff Bosch
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another quick point:
I would explicitly test for the boolean "true": if ( isCurrent() == true ).
Then, you don't really need "else if" because you've already done the test. The else-if can be reduced to a simple else{} block.
 
reply
    Bookmark Topic Watch Topic
  • New Topic