LinkedList int size() method Example Program


Returns the number of elements in this list.

Program

package com.candidjava;

import java.util.LinkedList;

/**
 * 
 * @author : mohan
 * @description :The java.util.LinkedList.size() method returns the number of
 *              elements in this list.
 */
public class LinkedListSize {
	public static void main(String[] args) {
		LinkedList list = new LinkedList();
		list.add("anandh");
		list.add("hari");
		list.add("vinoth");
		list.add("mohan");
		list.add("kamal");
		list.add("vinoth");
		System.out.println("LinkedList:" + list);
		System.out.println("List size:" + list.size());
		list.add("Coffee");
		list.add("Element");
		System.out.println("LinkedList:" + list);
		System.out.println("List size:" + list.size());
	}
}

Output

LinkedList:[anandh, hari, vinoth, mohan, kamal, vinoth]
List size:6
LinkedList:[anandh, hari, vinoth, mohan, kamal, vinoth, Coffee, Element]
List size:8

Explanation

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

Specified by:
size in interface Collection<E>

Specified by:
size in interface Deque<E>

Specified by:
size in interface List<E>

Specified by:
size in class AbstractCollection<E>

Returns:
the number of elements in this list


Related Post

Comments


©candidjava.com