LinkedList - isEmpty, size and clear methods program in java







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>

ArrayList - add, add element at specific index methods program


ArrayList - remove, get, contains and set methods program


ArrayList - iterate using iterator, listIterator, Enumeration and enhanced for loop


ArrayList - fail-safe or fail-fast iteration using iterator, listIterator, Enumeration and enhanced for loop


ArrayList - synchronizing using Collections.synchronizedList


ArrayList - making list unmodifiable using Collections.unmodifiableList


Vector - add, add element at specific index methods program


No comments:

Post a Comment