The size() method of CopyOnWriteArrayList returns the size of the list. It returns the number of elements in the list.
Syntax:
public int size()
Parameters: The function does not accepts any parameter.
Return Value: The function returns the size of the list.
Below programs illustrate the above function:
Program 1:
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.*;
public class GFG {
public static void main(String[] args)
{
CopyOnWriteArrayList<Integer> ArrLis
= new CopyOnWriteArrayList<Integer>();
ArrLis.add( 32 );
ArrLis.add( 67 );
ArrLis.add( 98 );
ArrLis.add( 100 );
System.out.println( "CopyOnWriteArrayList: "
+ ArrLis);
System.out.println( "size of ArrLis: "
+ ArrLis.size());
}
}
|
Output:
CopyOnWriteArrayList: [32, 67, 98, 100]
size of ArrLis: 4
Program 2:
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.*;
public class GFG {
public static void main(String[] args)
{
CopyOnWriteArrayList<String> ArrLis
= new CopyOnWriteArrayList<String>();
ArrLis.add( "gopal" );
ArrLis.add( "gfg" );
ArrLis.add( "jgec" );
ArrLis.add( "sudo" );
System.out.println( "CopyOnWriteArrayList: "
+ ArrLis);
System.out.println( "size of ArrLis: "
+ ArrLis.size());
}
}
|
Output:
CopyOnWriteArrayList: [gopal, gfg, jgec, sudo]
size of ArrLis: 4
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CopyOnWriteArrayList.html#size–
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
26 Nov, 2018
Like Article
Save Article