YouTip LogoYouTip

Java Arraylist Size

# Java ArrayList size() Method [![Image 3: Java ArrayList](#) 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. [![Image 4: Java ArrayList](#) Java ArrayList](#)
← Python3 Att List RemovePython3 Att List Extend β†’