3:53 pm - Friday March 25, 0118

Stack 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 StackLastIndexOf
{
public static void main(String arg[])throws Exception
{
Stack s=new Stack();//to create object for Stack class
s.add("ap");//to add an element in Stack
s.add("ba");//to add an element in Stack
s.add("ca");//to add an element in Stack
s.add("or");//to add an element in Stack
s.add("or");//to add an element in Stack
System.out.println(s);
System.out.println("index for or:"+s.lastIndexOf("or"));//to get index value for specfied element occurring at last
System.out.println("index for ca:"+s.lastIndexOf("f"));//to get index value for specfied element occurring at last
}
}

OUTPUT:
[ap, ba, ca, or]
index for or:4
index for ca:-1

BACK

Filed in: Z-A All Java Codes

Comments are closed.