Sunday 25 May 2014

LinkedList : size : Get the size of the List

public int size()
Returns the number of elements in this list.

import java.util.*;

class LinkedListSize{
 public static void main(String args[]){
  LinkedList<Integer> myList;
  myList = new LinkedList<> ();
  
  /* Add Elements to myList */
  myList.add(10);
  myList.add(20);
  myList.add(30);
  myList.add(40);
  
  System.out.println("Elements in myList are");
  System.out.println(myList);
 
  System.out.print("Number Of Elements in myList are ");
  System.out.println(myList.size());
 }
}

Output
Elements in myList are
[10, 20, 30, 40]
Number Of Elements in myList are 4


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment