[java] How to find the length of an array list?

I don't know how to find the length of an array list. I think you might need to use blank.length(); but I'm not sure.

I made an array list

ArrayList<String> myList = new ArrayList<String>();

but how do I write code to print out the size of myList?

This question is related to java arraylist

The answer is


System.out.println(myList.size());

Since no elements are in the list

output => 0

myList.add("newString");  // use myList.add() to insert elements to the arraylist
System.out.println(myList.size());

Since one element is added to the list

output => 1