8:59 am - Thursday February 22, 2018

ArrayList Example Program for 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
/**
*@author :CandidJava.com
*@descriptions : This program explain the function and use of
lastIndexOf(Object o).It is used to  get index value for specfied element occurring at last
*/
import java.io.*;
import java.util.*;
public class ArrayListLastIndexOf
{
public static void main(String arg[])throws Exception
{
ArrayList al=new ArrayList();//to create object for ArrayList class
al.add("a");//to add an element in arrayList
al.add("b");//to add an element in arrayList
al.add("c");//to add an element in arrayList
al.add("e");//to add an element in arrayList
al.add("c");//to add an element in arrayList
System.out.println(al);
System.out.println("index for c:"+al.lastIndexOf("c"));//to get index value for specfied element occurring at last
System.out.println("index for d:"+al.lastIndexOf("d"));//to get index value for specfied element occurring at last
}
}

Output:
[a, b, c, e, c]
index for c:4
index for d:-1

BACK

Filed in: Z-A All Java Codes

Comments are closed.