This week's book giveaway is in the Other Open Source APIs forum. We're giving away four copies of Storm Applied and have Sean Allen, Peter Pathirana & Matthew Jankowski on-line! See this thread for details.
Just to clarify a bit, does this include searching for the item? If so, is the array sorted? When something is removed from the middle, do the components further down the array all need to slide over a notch, preserving the order, or does anything need to fill in the new empty space?
Well, yeah, this is certainly the fastest. Wether it's actually doing what you want depends on your answers to Dirk questions, though...
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Joined: Mar 08, 2004
HI Derk Yes order need to me maintained and the array is sorted. What can be the solution then.I dont want to go with null option. THanks kundan
Do you even need to use an array? Sounds like a TreeSet may be worth considering here (unless you need to allow duplicates). Alternately, perhaps a LinkedList, or even ArrayList. Depends what else you're doing with the data. If you must use an array, then you should probably use System arraycopy() to shift the latter part of the array one slot to the left, as efficiently as possible. You'll have a null at the end, but that's the price of using an array, I think. Unless you want to recopy the whole array to another which is one element smaller, which seems rather wasteful from a performance perspective.
I suspect the solution is different depending on how many elements you want to remove. I would add "how many elements have to be removed" to Dirk's questions. If the number to be removed is a large fraction of the total, building a new array is probably fastest.