This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
When running this shuffler program I expect to get five random objects and then a null at the end. But I`m getting six objects in output when I got 5 declared. I think it`s because I don`t know how to use the Iterator.remove() method properly. Here`s the code:
PS! the two calls to hand is always the same. Thanks for any help!
Hi Haakon, The iterator is working fine. The problem is that hand still holds the value from the previous assignment. Try using hand[size + 3] in the second loop and dump hand, hand and hand instead and see what happens. Michael Morris
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Joined: Sep 18, 2002
Thanks Michael, didn`t see that it couldn`t cast a null as it skips the last code on hand and thus the old object is still in place. Got a ....OutOfBoundsException when i tried your tip, but I threw in this at the end instead:
So now it works Thanks again, Haakon
Joined: Jan 30, 2002
Got a ....OutOfBoundsException when i tried your tip, but I threw in this at the end instead:
That's why I told you to do it that way so you could see what was going on, ie that the second loop only had two iterations, otherwise the Exception would have occurred in the loop instead of the Sysout. Michael Morr
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com