How to find the length of an array list?

JavaArraylist

Java Problem Overview


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?

Java Solutions


Solution 1 - Java

Solution 2 - Java

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1254044View Question on Stackoverflow
Solution 1 - JavaAdam ReedView Answer on Stackoverflow
Solution 2 - JavaSergej RaishinView Answer on Stackoverflow