Java Arraylist Size
# Java ArrayList size() Method
[ Java ArrayList](#)
size() MethodUsed to return the number of elements in a dynamic Array.
size() MethodThe syntax is:
arraylist.size()
**NoteοΌ**arraylist is ArrayList Classan object of.
**Parameter Description:**
* None
### Return Value
Returns the number of elements in the Array.
### Example
Get the length of a dynamic Array:
## Example
import java.util.ArrayList;
class Main {
public static void main(String[] args){
// Create a dynamic Array
ArrayList sites =new ArrayList();
sites.add("Google");
sites.add("");
sites.add("Taobao");
System.out.println("Website List: "+ sites);
// Get the Number of Elements in the Array
int size = sites.size();
System.out.println("Dynamic Array Length: "+ size);
}
}
The output after executing the above program is:
Website List: [Google, , Taobao]Dynamic Array Length: 3
In the above example, we created a dynamic Array named sites, and then used the size() Method to get the number of elements in the dynamic Array.
[ Java ArrayList](#)
YouTip