8:12 am - Tuesday November 21, 2017

Retrieve the last index position of an object int lastIndexOf(Object o)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

                                         This method returns the index value of the last occurrence of the specified element in the list. This method returns negative value if the specified element is not present in the list.

Example Program

import java.util.ArrayList;

public class LastIndex
{

   public static void main(String[] args)

    {

       ArrayList<String> al=new ArrayList<String>();

       System.out.println("Concepts in java:");

       al.add("Constructor");

       al.add("Inheritance");

       al.add("Polymorphism");

       al.add("Exceptional Handling");

       al.add("Inheritance");

       al.add("Casting");

       al.add("Packages");

       System.out.println(al);

       System.out.println("Last Occurrence Value");

       int i=al.lastIndexOf("Inheritance");

       System.out.println("The Index value for the inheritance is:" +i);

    }

}

Output

    Concepts in java:

    [Constructor, Inheritance, Polymorphism, Exceptional Handling, Inheritance, Casting, Packages]

    Last Occurrence Value

    The Index value for the inheritance is:4

BACK

Filed in: Java Examples

Comments are closed.