469,328 Members | 1,327 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Get the last item in ArrayList

I have an ArrayList outputList. I only need to get the last item:

int last = outputList.LastIndexOf(null);
ExtremeBucket lastItem =
(ExtremeBucket)outputList[last];

Please confirm if this is the right way. Thanks!
Oct 24 '08 #1
5 13835
No, to get the last item in the list, use

int last = outputList [outputList.Count () - 1];

I have no idea how you are converting an int to an ExtremeBucket though.

"Curious" <fi********@yahoo.comwrote in message
news:2c**********************************@v30g2000 hsa.googlegroups.com...
>I have an ArrayList outputList. I only need to get the last item:

int last = outputList.LastIndexOf(null);
ExtremeBucket lastItem =
(ExtremeBucket)outputList[last];

Please confirm if this is the right way. Thanks!
Oct 24 '08 #2
Family Tree Mike:

Thanks! FYI, I used the following approach you've suggested:

ExtremeBucket lastItem =
(ExtremeBucket)outputList[outputList.Count - 1];

Each item is type of ExtremeBucket.
Oct 24 '08 #3
On Fri, 24 Oct 2008 14:39:50 -0700 (PDT), Curious
<fi********@yahoo.comwrote:
>Family Tree Mike:

Thanks! FYI, I used the following approach you've suggested:

ExtremeBucket lastItem =
(ExtremeBucket)outputList[outputList.Count - 1];

Each item is type of ExtremeBucket.
You should consider using the generic List instead of ArrayList. That
way your access to the list will be type safe.
Oct 24 '08 #4
I agree with Jack, that List<ExtremeBucketwill be better for you in the
long run.

"Curious" <fi********@yahoo.comwrote in message
news:69**********************************@m44g2000 hsc.googlegroups.com...
Family Tree Mike:

Thanks! FYI, I used the following approach you've suggested:

ExtremeBucket lastItem =
(ExtremeBucket)outputList[outputList.Count - 1];

Each item is type of ExtremeBucket.
Oct 25 '08 #5
I agree with Jack, that List<ExtremeBucketwill be better for you in the
long run.
I do intend to use List<ExtremeBucket>. However, since this must be
coded in Visual Studio 2003 (which is compatible with .NET 1.1), I
have to use ArrayList because it doesn't recognize generic.
Oct 27 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Tomek R. | last post: by
2 posts views Thread by David Lozzi | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.