473,785 Members | 2,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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*****@tvsinfo tech.com

May 10 '06 #1
4 71119
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********@gma il.com> wrote in message
news:11******** **************@ u72g2000cwu.goo glegroups.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*****@tvsinfo tech.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*****@tvsinfo tech.com

May 10 '06 #4

"None" <vi********@gma il.com> wrote in message
news:11******** **************@ u72g2000cwu.goo glegroups.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.ToArr ay
May 10 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
55571
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 also removed) So far I have (val is value, ar is array, returns new array):
6
1785
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: 1,3,6,12,13,14,15 Any help ??
11
2747
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
6484
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
3810
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 isn't working. It neither removes the item from the arraylist nor from the combobox like it's supposed to do. A couple of notes: cbx is the name of the combobox within my usercontrol, file is the name of the arraylist within my usercontrol. To try...
4
9830
by: eksamor | last post by:
I have a simple linked list: struct element { struct element *next; int start; }; struct list { struct element *head;
14
3049
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 deleting the last element. Can someone help please Thank you all Olga I just wanted to test my function,so don't bother with main, and print
11
4511
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 rows inserted/sec up to 500, and 100rows/6secs up to 3000, which isn't great but then the Row Count is clicking away for the user to see and they can hit the "cancel" button at anytime, so overall I'm happy), what really disappoints me is the...
3
5611
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 delete the lines from the log file before loading in the array took ages, i thought i would be alot quicker to put in an array and remove the unwanted lines. Dim text As Array Dim lines As New List(Of String)
6
5503
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
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9481
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8978
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.