469,636 Members | 1,558 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,636 developers. It's quick & easy.

Remove the element from array

Hi,

I have declared array as Int[] ids = new int[50];

In ArrayList we can remove specified index using RemoveAt(5)
method. My question is how can we do this one with int array (single
dimensional array) or else is there any alternative solution for this?

If anybody knows the solution pls let me know.

Thanks and Regards,
Vinothkumar B
bv*****@tvsinfotech.com

May 10 '06 #1
4 70875
You can't remove an item from an array you could say set the position to
null for an array of a reference type .. Arrays are a fixed size data
structure ..

when you define an array of int [50] think about it creating 50 ints one
after another .. the array points to the first 1 ... so array[22] points to
the memory address of array[0] + 22 * size of your data. In order to remove
an index you would have to recreate the array

Cheers,

Greg Young
MVP - C#
"None" <vi********@gmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
Hi,

I have declared array as Int[] ids = new int[50];

In ArrayList we can remove specified index using RemoveAt(5)
method. My question is how can we do this one with int array (single
dimensional array) or else is there any alternative solution for this?

If anybody knows the solution pls let me know.

Thanks and Regards,
Vinothkumar B
bv*****@tvsinfotech.com

May 10 '06 #2
V
You could of course write a wrapper over your array which would move
each of the items below the deleted item one step up.

This would be VERY ineffcient of course, but depends on your
requirements.

Regards,
Vaibhav

May 10 '06 #3
Interesting ... Microsoft Implements ArrayList as internal array of object
references to your value or referene types. As ArrayList maintains references
so removeat(5) means that object reference will be done null and that
particular element is finalized and references are refreshed that is
arraylist[i] references to arraylist[i+1]. Its very easy to do if array is
object array ... but if you are creating an array of like int or string (any
value type ) then its very tedious.

"None" wrote:
Hi,

I have declared array as Int[] ids = new int[50];

In ArrayList we can remove specified index using RemoveAt(5)
method. My question is how can we do this one with int array (single
dimensional array) or else is there any alternative solution for this?

If anybody knows the solution pls let me know.

Thanks and Regards,
Vinothkumar B
bv*****@tvsinfotech.com

May 10 '06 #4

"None" <vi********@gmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
Hi,

I have declared array as Int[] ids = new int[50];

In ArrayList we can remove specified index using RemoveAt(5)
method. My question is how can we do this one with int array (single
dimensional array) or else is there any alternative solution for this?


If arrays could do everything ArrayList does then there would be no need for
ArrayList.

Removing stuff from an array is never going to be efficient however you do
it so just use ArrayList and ArrayList.ToArray
May 10 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Sam Collett | last post: by
11 posts views Thread by koperenkogel | last post: by
7 posts views Thread by Derek Basch | last post: by
4 posts views Thread by eksamor | last post: by
14 posts views Thread by oLgAa25 | last post: by
11 posts views Thread by Richard Maher | last post: by
3 posts views Thread by Barkingmadscot | last post: by
6 posts views Thread by tedpottel | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.