How to get the size of LinkedList?
Previous | Home | Next |
This program will shows how to get the size of the LinkedList
Size () of LinkedList class is used to get the size of the Linkedlist
Public int size() returns the size of LinkedList in integer
package Example;
import java .util.LinkedList;
import java .util.Iterator;
public class LinklistExample {
/**
* @param args
*/
public static void main(String[] args) {
LinkedList Lst= new LinkedList(); // create object of LinkedList
// add elements to the LinkedList using add method
Lst.add("4");
Lst.add("6");
Lst.add("8");
Lst.add("10");
Lst.add("12");
Lst.add("14");
Lst.add("16");
Lst.add("18");
System.out.println("The elements of LinkedList prior to addition of other elemnts are:"+Lst);
Lst.size()
System.out.println("The size of LinkeList is:"+Lst.size());
The size of LinkedList is : 7
Previous | Home | Next |