3:07 pm - Monday January 16, 2017

Program that returns number of elements in the Arraylist

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

This program is used to returns number of elements in the ArrayList.

Example Program


package com.example;

import java.util.*;

public class LinkedListPoll {
	public static void main(String[] args) // create a LinkedList

	{
		LinkedList list = new LinkedList(); // add some elements
		list.add("Hello");
		list.add(2);
		list.add("Chocolate");
		list.add("10");
		// print the list
		System.out.println("LinkedList:" + list); // retrieve and remove the
													// head of the list
		System.out.println("Head element of the list:" + list.poll()); // print
																		// the
																		// list
		System.out.println("LinkedList:" + list);
	}
}


output:

Number = 25

Number = 10

Number = 20

Number = 35

Size of list = 4

Explnation:

public int size()

Returns the number of elements in this list.

Specified by:

size in interface Collection<E>

Specified by:

size in interface List<E>

Specified by:

size in class AbstractCollection<E>

Returns:

the number of elements in this list

BACK

 

Filed in: Java Examples

Comments are closed.