ArrayList methods

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shana07
    Contributor
    • Jan 2007
    • 280

    #1

    ArrayList methods

    Kindly please someone who knows how to get last Entry in ArrayList?
    Please share with me..thanks

    Code:
    void methodA
    { ....
    while ( myArrayList. ??? ) // how to get the last Entry? 
    { 
       // in last Entry of ArrayList need to call methodB
    }
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by shana07
    Kindly please someone who knows how to get last Entry in ArrayList?
    Please share with me..thanks

    Code:
    void methodA
    { ....
    while ( myArrayList. ??? ) // how to get the last Entry? 
    { 
    // in last Entry of ArrayList need to call methodB
    }
    Go to the ArrayList docs and see the methods there.

    Comment

    • shana07
      Contributor
      • Jan 2007
      • 280

      #3
      Originally posted by r035198x
      Go to the ArrayList docs and see the methods there.
      sorry, kindly please give hint to me at least answer is this possible to achieve?
      Code:
      the last entry in ArrayList {
      //calls other method.
      I found: one method, but I think that's not what I want - the object o part.
      Code:
       firstArrayList.lastIndexOf(Object o)

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by shana07
        sorry, kindly please give hint to me at least answer is this possible to achieve?
        Code:
        the last entry in ArrayList {
        //calls other method.
        I found: one method, but I think that's not what I want - the object o part.
        Code:
         firstArrayList.lastIndexOf(Object o)
        The get method gives you the option of providing the position. get(int i).
        No all you need is to provide the last position of the Arraylist ...

        Comment

        • Kulbir Singh
          New Member
          • Apr 2007
          • 2

          #5
          Originally posted by shana07
          Kindly please someone who knows how to get last Entry in ArrayList?
          Please share with me..thanks

          Code:
          void methodA
          { ....
          while ( myArrayList. ??? ) // how to get the last Entry? 
          { 
             // in last Entry of ArrayList need to call methodB
          }

          try this code

          ArrayList list = new ArrayList();
          list.add("a");
          list.add("b");
          list.add("s");
          list.add("S");
          list.add("F");
          list.add("a");
          list.add("h");

          int size = list.size()-1;
          System.out.prin tln("last element " +list.get(size) );

          regards
          Kulbir Singh

          Comment

          Working...