LinkedList E remove() method Example Program


Retrieves and removes the head (first element) of this list.

Program

package com.candidjava;

import java.util.LinkedList;

/**
 * 
 * @author : mohan
 * @description :The java.util.LinkedList.remove() method retrieves and removes
 *              the head (first element) of this list.
 */
public class LinkedListRemove {

	public static void main(String[] args) {

		LinkedList<Comparable> list = new LinkedList();

		list.add("mohan");
		list.add("kamal");
		list.add("siva");
		list.add("sankar");
		System.out.println("LinkedList:" + list);
		list.remove();
		System.out.println("LinkedList:" + list);
	}
}

Output

LinkedList:[mohan, kamal, siva, sankar]
LinkedList:[kamal, siva, sankar]

Explanation

public E remove()
Retrieves and removes the head (first element) of this list.

Specified by:
remove in interface Deque<E>

Specified by:
remove in interface Queue<E>

Returns:
the head of this list

Throws:
NoSuchElementException - if this list is empty

Since:
1.5


Related Post

Comments


©candidjava.com