void clear() method Example Program


Removes all of the elements from this list. The list will be empty after this call returns.

Program

package com.candidjava;

import java.util.LinkedList;

/**
 * 
 * @author : mohan
 * @description :The java.util.LinkedList.clear() method removes all of the
 *              elements from this list.
 */
public class LinkedListClear {
	public static void main(String[] args) {
		LinkedList list = new LinkedList();
		list.add("anandh");
		list.add("hari");
		list.add("vinoth");
		list.add("kamal");
		System.out.println("LinkedList:" + list);
		list.clear();
		System.out.println("LinkedList:" + list);
	}
}

Output

LinkedList:[anandh, hari, vinoth, kamal]
LinkedList:[]

Explanation

public void clear()
Removes all of the elements from this list. The list will be empty after this call returns.

Specified by:
clear in interface Collection

Specified by:
clear in interface List

Overrides:
clear in class AbstractList


Related Post

Comments


©candidjava.com