473,394 Members | 1,761 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,394 software developers and data experts.

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 3732
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.com>
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.com>
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)arrayList[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**********************************@microsof t.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.com>
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
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...
4
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
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...
5
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...
7
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...
6
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...
18
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...
6
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...
0
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.