473,226 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

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 71076
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are...
6
by: Rimuen | last post by:
Have a string contains numbers from database. But there is similar numbers want to remove Example: 1,3,6,6,6,12,13,14,15,15,15,15 Want to remove the similar numbers so it would be like:...
11
by: koperenkogel | last post by:
Dear cpp-ians, I am working with a vector of structures. vector <meta_segment> meta_segm (2421500); and the structure look like: struct meta_segment { float id; float num;
7
by: Derek Basch | last post by:
I can remove objects from an array by doing this: for (i in oCache){ if (i == "test"){ delete oCache; }; }; However, the array's length property is unaffected.
3
by: Don | last post by:
My user control has a combobox with an arraylist attached to it along with custom add and remove methods. The "Add" method is working great. However I don't understand why the "Remove" method...
4
by: eksamor | last post by:
I have a simple linked list: struct element { struct element *next; int start; }; struct list { struct element *head;
14
by: oLgAa25 | last post by:
Hello all, I am back I have this question everything compiles fine, but I just need to check for an index that is more than the array size. Although it says out of bound, but it is still...
11
by: Richard Maher | last post by:
Hi, I have read many of the copius entries on the subject of IE performance (or the lack thereof) when populating Select Lists. I don't mind the insert performance so much, (I get 100x120byte...
3
by: Barkingmadscot | last post by:
I am stuck, i can workout how to remove lines from an array I have loading a text file (a Log), I know which lines a need, but the logs can be upto 30K sometimes bigger. I found trying to...
6
by: tedpottel | last post by:
Help How can I remove an item from an array, Example Array=3, array=6 array=7 array=9 Is there a way to remove a item, say index 1, so the array would now be Array=3 array=7 array=9 ?????
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.