2:19 am - Tuesday October 24, 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


import java.util.ArrayList;

class Arraysize {
public static void main(String[] args) {

// create an empty array deque with an initial capacity
ArrayList<Integer> arrlist = new ArrayList<Integer>(5);

// use add() method to add elements in the deque
arrlist.add(25);
arrlist.add(10);
arrlist.add(20);
arrlist.add(35);

// printing all the elements available in list
for (Integer number : arrlist) {
System.out.println("Number = " + number);
}

int retval = arrlist.size();
System.out.println("Size of list = " + retval);
}
}

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: Z-A All Java Codes

Comments are closed.