473,770 Members | 6,091 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing Arraylist Collection

JJ
Hi,

I have created an Arraylist object from an Arraylist class.
I added rows to the arraylist object and I need to find a particular record
in my arraylist. How do I do this? Also if I was in the middle of building
the arraylist and wanted to call the last record added to arraylist object
how can I do this?

Thanks,

JJ
Nov 16 '05 #1
3 3757
JJ <JJ@discussions .microsoft.com> wrote:
I have created an Arraylist object from an Arraylist class.
I added rows to the arraylist object and I need to find a particular record
in my arraylist. How do I do this?
Do you mean by row number, or by row object? If it's by row object, use
IndexOf. If it's by row number, use the indexer:

object o = arrayList[rowNumber];
Also if I was in the middle of building the arraylist and wanted to
call the last record added to arraylist object how can I do this?


Use the indexer again, along with the Count property:

object last = arrayList[arrayList.Count-1];

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
JJ
ok so how would I update a record in an arrowlist? So how would I be able to
check or get individual items of arraylist?

Thanks,

JJ

"Jon Skeet [C# MVP]" wrote:
JJ <JJ@discussions .microsoft.com> wrote:
I have created an Arraylist object from an Arraylist class.
I added rows to the arraylist object and I need to find a particular record
in my arraylist. How do I do this?


Do you mean by row number, or by row object? If it's by row object, use
IndexOf. If it's by row number, use the indexer:

object o = arrayList[rowNumber];
Also if I was in the middle of building the arraylist and wanted to
call the last record added to arraylist object how can I do this?


Use the indexer again, along with the Count property:

object last = arrayList[arrayList.Count-1];

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
JJ,

It works pretty much like an array of objects except that the number of
elements is dynamic rather than fixed. To update:

arrayList[rowNumber] = newThing;

To extract an item:

object oldThing = arrayList[rowNumber];

I'm leaving out casting; if the items in the arraylist are of a particular
type, say MyType:

MyType oldThing = (MyType)arrayLi st[rowNumber];

You should Google and read one of the basic tutorials and/or check out the
help for ArrayList -- particularly the Add(), AddRange(), IndexOf(),
Remove() and RemoveAt() methods, the Count property and of course the Item
property (indexer in C#) which I've focused on above.

--Bob

"JJ" <JJ@discussions .microsoft.com> wrote in message
news:FC******** *************** ***********@mic rosoft.com...
ok so how would I update a record in an arrowlist? So how would I be able
to
check or get individual items of arraylist?

Thanks,

JJ

"Jon Skeet [C# MVP]" wrote:
JJ <JJ@discussions .microsoft.com> wrote:
> I have created an Arraylist object from an Arraylist class.
> I added rows to the arraylist object and I need to find a particular
> record
> in my arraylist. How do I do this?


Do you mean by row number, or by row object? If it's by row object, use
IndexOf. If it's by row number, use the indexer:

object o = arrayList[rowNumber];
> Also if I was in the middle of building the arraylist and wanted to
> call the last record added to arraylist object how can I do this?


Use the indexer again, along with the Count property:

object last = arrayList[arrayList.Count-1];

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #4

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

Similar topics

6
2865
by: Jon Agiato | last post by:
Hello all, Here is the jist of my situation: I have an ArrayList of class A. class A contains a Stack of class B. I need to add instances of class B to the Stack in each instance of class A within the ArrayList like so (except correct, hehe): classA.stackInA.add(new classB(blah)); The problem is, this syntax gives me the following error:
4
7088
by: Tamir Khason | last post by:
How can I set the type of the object added to ArrayList (type of Array List Members) Here is the code: protected ArrayList tabs = new ArrayList(); public ArrayList Tabs {
0
1722
by: Jason Coyne Gaijin42 | last post by:
I have seen several people looking for a way to access the Columns collection when using the AutoGenerate = true option. Some people have gotten so far as to find the private autoGenColumnsArray that has the information, but we as developers have no way to access this information. I have come up with a solution for the problem, (as I am sure many others have) using reflection. Here is some sample code that will print out the auto...
5
6293
by: Jack Addington | last post by:
How do I go about accessing elements of an Arraylist using something other than the index? I have a class that manages a number of subclasses. Those subclasses are stored in an arraylist. The subclass has a key property that is a string. I would like to be able to call Class1.SubClassManager as opposed to Class1.SubClassManager. I tried overriding ArrayList but then I wasn't sure what method to then override or if there was a...
7
23545
by: MrNobody | last post by:
since ArrayList implements ICollection, is there a quick way to convert an ICollection into ArrayList (besides actually iterating through each element in the ICollection and explicitly adding them to a new ArrayList instance) ??
6
1462
by: GrandpaB | last post by:
While writing this plea for help, I think I solved my dilemma, but I don't know why the problem solving statement is necessary. The inspiration for the statement came from an undocumented VB example I found on the web. I would be most appreciative if someone could explain why this statement is necessary and what does it do: MyArt = New Art
18
3254
by: Sam | last post by:
Hi All I'm planing to write an application which allows users dynamically add their points (say you can add upto 30,000) and then draw xy graph. Should I use an array for my coordinate point storage and dynamically resize it when there is a new point or should I use ArrayList? Is speed noticable between the two? Regards,
6
3141
by: fniles | last post by:
I am using VB.NET 2003 and a socket control to receive and sending data to clients. As I receive data in 1 thread, I put it into an arraylist, and then I remove the data from arraylist and send it to the client. Before adding data to the arraylist, I check if the depth of the arraylist is longer than iMaxQueueDepth, and if it is, I clear the arraylist. Is it possible that while I am clearing the arraylist, the ThreadMain at the same time...
0
987
by: aine_canby | last post by:
Hi all, I have the following simple class which I use to store a set of lab objects: /// <summary> /// Represents a Collection of Labs /// </summary> public class CLabCollection {
0
9595
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
9432
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
10232
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
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
5313
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
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3974
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
2
3578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2822
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.