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

我只是一个虾纸丫 提交于 2019-12-17 07:04:10

问题


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?


回答1:


The size member function.

myList.size();

http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html




回答2:


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



来源:https://stackoverflow.com/questions/9652732/how-to-find-the-length-of-an-array-list

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!