-
July 8th, 2005, 08:58 AM
#1
How can I delete multiple items from collection?
Hello,
How do I delete multiple elements from collection (array) at once?
I'd like to do that by index.
For example, I want to delete elements with indexes 1, 2, 3 and 4.
If I delete element at index 1, all elements and their indexes will be shifted. That's the problem. I need to delete the elements in compact index section, like: 1,2,3,4 or 7,8,9,10.
Thank you in advance
Goran
-
July 8th, 2005, 09:00 AM
#2
Re: How can I delete multiple items from collection?
If this is an ArrayList you have a RemoveRange method which takes the start index and the number of elements to remove.
Darwen.
-
July 8th, 2005, 09:20 AM
#3
Re: How can I delete multiple items from collection?
A quick and dirty hack is to delete from the highest to the lowest index. So you will not getting in trouble with shifted indexes. Therefore you have to sort your indexes for removing in the right way.
For solving this problem in a good way you should use an ArrayList and the Remove()-method. So you do not get in trouble with any index.
Useful or not? Rate my posting. Thanks.
-
July 8th, 2005, 09:28 AM
#4
Re: How can I delete multiple items from collection?
Originally Posted by torrud
A quick and dirty hack is to delete from the highest to the lowest index. So you will not getting in trouble with shifted indexes. Therefore you have to sort your indexes for removing in the right way.
For solving this problem in a good way you should use an ArrayList and the Remove()-method. So you do not get in trouble with any index.
Try as torrud,darwen tol you you can do by that way .i mean to say just enter the index store all the index no in a array make a loop and use remove at and specify index no in it.
Second if you want to do it in simple array only
do same thing except after removing 1 element make a left shift to array element and then again perform the calculation.
it's apposite of insertion sort method forget sort for a while time
but you can get a idea by this that how it take place same way you can delete also
if still problem let me know
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|