LinkedList boolean removeLastOccurrence(Object o) method Example Program


Removes the last occurrence of the specified element in this list (when traversing the list from head to tail). If the list does not contain the element, it is unchanged.

Program

package com.candidjava;

import java.util.LinkedList;

/**
 * 
 * @author : mohan
 * @description :The java.util.LinkedList.removeLastOccurrence(Object o) method
 *              removes the last occurrence of the specified element in this
 *              list (when traversing the list from head to tail). If the list
 *              does not contain the element, it is unchanged.
 */
public class LinkedListRemovLastOccur {
	public static void main(String[] args) {

		LinkedList list = new LinkedList();

		list.add("anandh");
		list.add("hari");
		list.add("vinoth");
		list.add("mohan");
		list.add("kamal");
		list.add("vinoth");

		System.out.println("LinkedList:" + list);

		boolean found = list.removeLastOccurrence("vinoth");
		System.out.println("Element found:" + found);

		System.out.println("LinkedList:" + list);
	}

}

Output

LinkedList:[anandh, hari, vinoth, mohan, kamal, vinoth]
Element found:true
LinkedList:[anandh, hari, vinoth, mohan, kamal]

Explanation

public boolean removeLastOccurrence(Object o)
Removes the last occurrence of the specified element in this list (when traversing the list from head to tail). If the list does not contain the element, it is unchanged.

Specified by:
removeLastOccurrence in interface Deque<E>

Parameters:
o - element to be removed from this list, if present

Returns:
true if the list contained the specified element

Since:
1.6


Related Post

Comments


©candidjava.com