This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

AddAfter method

 
Jere Johnson
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • 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 ]
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • 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: 805
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic