3:53 pm - Monday March 25, 8830

LinkedList 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
Description: Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.
 */
import java.io.IOException;
import java.util.*;

public class LinkedListLastIndexOf {
	public static void main(String args[]) {
		boolean a;
		int b = 60, c = 20, d = 30, e, f = 60;
		LinkedList l = new LinkedList();
		a = l.add(b);
		a = l.add(c);
		a = l.add(d);
		a = l.add(f);
		e = l.lastIndexOf(c);// returns position of the last occurence of the
					// given element in the list
		System.out.println("the given element is " + c);
		System.out.println("position of the last occurrence of the given element in the list is"+ e);
	}
}

Output
the given element is 20
position of the last occurrence of the given element in the list is 1

Filed in: Z-A All Java Codes

Comments are closed.