3:42 am - Monday June 25, 2018

Stack Example Program for lastIndexOf(Object o,int index)

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(Obj o,int index)
 */
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("a");// to add an element in Stack
		s.add("b");// to add an element in Stack
		s.add("c");// to add an element in Stack
		s.add("e");// to add an element in Stack
		s.add("c");// to add an element in Stack
		System.out.println(s);
		System.out.println("index for c:" + s.lastIndexOf("c", 3));// to get index value for specified element occurring at last

                System.out.println("index for d:" + s.lastIndexOf("d", 1));// to get index value for specified element occurring at last

	}
}

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

Filed in: Z-A All Java Codes

Comments are closed.