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

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?

7

2 Answers

The size member function.

myList.size();
1
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

You Might Also Like