3:44 pm - Friday December 11, 8167

ArrayList Example Program for indexOf(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
int  indexOf(Object o).It is used get index value for specfied element
*/
import java.io.*;
import java.util.*;
public class ArrayListIndexOf
{
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
System.out.println(al);
System.out.println("index for c:"+al.indexOf("c"));//to get index value for specfied element
System.out.println("index for d:"+al.indexOf("d"));//to get index value for specfied element
}
}

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

BACK

Filed in: Z-A All Java Codes

Comments are closed.