Windows Vista Forums

Get the last item in ArrayList
  1. #1


    Curious Guest

    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!



      My System SpecsSystem Spec

  2. #2


    Family Tree Mike Guest

    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@xxxxxx> wrote in message
    news:2cccbb3d-cbdd-49e6-8b76-992404df2fa0@xxxxxx

    >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!

      My System SpecsSystem Spec

  3. #3


    Curious Guest

    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.

      My System SpecsSystem Spec

  4. #4


    Jack Jackson Guest

    Re: Get the last item in ArrayList

    On Fri, 24 Oct 2008 14:39:50 -0700 (PDT), Curious
    <fir5tsight@xxxxxx> wrote:

    >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.

      My System SpecsSystem Spec

  5. #5


    Family Tree Mike Guest

    Re: Get the last item in ArrayList

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

    "Curious" <fir5tsight@xxxxxx> wrote in message
    news:691b4373-6e3e-445a-a9e0-8083992fcd40@xxxxxx

    > 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.

      My System SpecsSystem Spec

  6. #6


    Curious Guest

    Re: Get the last item in ArrayList


    > I agree with Jack, that List<ExtremeBucket> will 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.

      My System SpecsSystem Spec

Get the last item in ArrayList problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
rename-item, move-item and special chars. sardinian_guy PowerShell 3 26 Jul 2009
Empty Arraylist is null? Lars Zeb PowerShell 3 01 Apr 2009
Copy-Item : Container cannot be copied onto existing leaf item. Steve PowerShell 3 17 Mar 2009
Marshalling ArrayList Saad .NET General 0 26 Sep 2008
Thread-safety: Change property of items in arraylist versus removingitems from the arraylist Curious .NET General 2 06 Aug 2008