Connecting Tech Pros Worldwide Forums | Help | Site Map

Get the last item in ArrayList

Curious
Guest
 
Posts: n/a
#1: Oct 24 '08
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!
Family Tree Mike
Guest
 
Posts: n/a
#2: Oct 24 '08

re: Get the last item in ArrayList


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" <fir5tsight@yahoo.comwrote in message
news:2cccbb3d-cbdd-49e6-8b76-992404df2fa0@v30g2000hsa.googlegroups.com...
Quote:
>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!
Curious
Guest
 
Posts: n/a
#3: Oct 24 '08

re: Get the last item in ArrayList


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.
Jack Jackson
Guest
 
Posts: n/a
#4: Oct 25 '08

re: Get the last item in ArrayList


On Fri, 24 Oct 2008 14:39:50 -0700 (PDT), Curious
<fir5tsight@yahoo.comwrote:
Quote:
>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.
Family Tree Mike
Guest
 
Posts: n/a
#5: Oct 25 '08

re: Get the last item in ArrayList


I agree with Jack, that List<ExtremeBucketwill be better for you in the
long run.

"Curious" <fir5tsight@yahoo.comwrote in message
news:691b4373-6e3e-445a-a9e0-8083992fcd40@m44g2000hsc.googlegroups.com...
Quote:
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.
Curious
Guest
 
Posts: n/a
#6: Oct 27 '08

re: Get the last item in ArrayList


Quote:
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.
Closed Thread