Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #10238
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Delete slot in the middle of an array and shift remaining |
| Date | 2011-11-25 13:35 -0800 |
| Organization | Canadian Mind Products |
| Message-ID | <au10d7lg8vq323geunogvunmcgr9kb44p8@4ax.com> (permalink) |
| References | <4ecf7078$0$6582$9b4e6d93@newsspool3.arcor-online.net> |
On 25 Nov 2011 10:39:52 GMT, Svenfischer2@email.com (Sven Fischer) wrote, quoted or indirectly quoted someone who said : >How can I do this most easily? >Is this possible without iteration in a "while" loop? The easy and standard way to do this is to use an ArrayList. It has a method to do this. Arrays are for groups of elements where you do not add or remove after initial creation. see http://mindprod.com/jgloss/arraylist.html A slightly more hairy-chested way to do it is to use System.arraycopy which is a native method that can take advantage of the hardware's ability to move whacking hunks of bytes around at a time. see http://mindprod.com/jgloss/array.html To do it the Pascalan way you need a loop that maintains two indexes from and to. They both increment/decrement each time around the loop. If there is overlap, you must work either up or down to avoid overwriting. see http://mindprod.com/jgloss/jcheat.html for hints on how to do loops with two indexes. You can peek inside the ArrayList code to see how it handles inserting and deleting. look inside src.zip. This takes me back. I wrote various moves that implemented this logic for BBL Forth/Abundance. -- Roedy Green Canadian Mind Products http://mindprod.com I can't come to bed just yet. Somebody is wrong on the Internet.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Delete slot in the middle of an array and shift remaining Svenfischer2@email.com (Sven Fischer) - 2011-11-25 10:39 +0000
Re: Delete slot in the middle of an array and shift remaining Lew <lewbloch@gmail.com> - 2011-11-25 03:21 -0800
Re: Delete slot in the middle of an array and shift remaining Magnus Warker <magnux@mailinator.com> - 2011-11-25 18:44 +0100
Re: Delete slot in the middle of an array and shift remaining Lew <lewbloch@gmail.com> - 2011-11-25 09:55 -0800
Re: Delete slot in the middle of an array and shift remaining Arne Vajhøj <arne@vajhoej.dk> - 2011-11-25 21:22 -0500
Re: Delete slot in the middle of an array and shift remaining Sven Fischer <svenfischer2@email.com> - 2011-11-26 13:48 +0100
Re: Delete slot in the middle of an array and shift remaining Gene Wirchenko <genew@ocis.net> - 2011-11-26 21:25 -0800
Re: Delete slot in the middle of an array and shift remaining Patricia Shanahan <pats@acm.org> - 2011-11-25 10:17 -0800
Re: Delete slot in the middle of an array and shift remaining markspace <-@.> - 2011-11-25 10:24 -0800
Re: Delete slot in the middle of an array and shift remaining Lew <lewbloch@gmail.com> - 2011-11-25 11:26 -0800
Re: Delete slot in the middle of an array and shift remaining Arne Vajhøj <arne@vajhoej.dk> - 2011-11-25 21:17 -0500
Re: Delete slot in the middle of an array and shift remaining Roedy Green <see_website@mindprod.com.invalid> - 2011-11-25 14:15 -0800
Re: Delete slot in the middle of an array and shift remaining Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-25 08:08 -0500
Re: Delete slot in the middle of an array and shift remaining markspace <-@.> - 2011-11-25 07:39 -0800
Re: Delete slot in the middle of an array and shift remaining Roedy Green <see_website@mindprod.com.invalid> - 2011-11-25 13:35 -0800
Re: Delete slot in the middle of an array and shift remaining Arne Vajhøj <arne@vajhoej.dk> - 2011-11-25 21:16 -0500
csiph-web