LinkedList - isEmpty, size and clear methods program.
import java.util.LinkedList;
import java.util.List;
/**
* Copyright (c), AnkitMittal JavaMadeSoEasy.com
*/
public class LinkedListIsEmptySizeClearExample {
public static void main(String args[]) {
List<String> linkedList = new LinkedList<String>();
System.out.println("--------add element to end of list");
linkedList.add("ankit");
linkedList.add("mittal");
linkedList.add("javaMadeSoEasy");
System.out.println("linkedList = "+linkedList);
System.out.println("linkedList.isEmpty() = "+linkedList.isEmpty());
System.out.println("\n--------clear list - remove all elements from list");
linkedList.clear();
System.out.println("linkedList.isEmpty() = "+linkedList.isEmpty());
System.out.println("linkedList = "+linkedList);
}
}
/*OUTPUT
--------add element to end of list
linkedList = [ankit, mittal, javaMadeSoEasy]
linkedList.isEmpty() = false
--------clear list - remove all elements from list
linkedList.isEmpty() = true
linkedList = []
*/
|
RELATED LINKS>