Java 如何找到数组列表的长度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9652732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 05:39:55  来源:igfitidea点击:

How to find the length of an array list?

javaarraylist

提问by user1254044

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.

我不知道如何找到数组列表的长度。我认为您可能需要使用,blank.length();但我不确定。

I made an array list

我做了一个数组列表

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

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

但是如何编写代码来打印出 myList 的大小?

回答by Sergej Raishin

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

Since no elements are in the list

由于列表中没有元素

output => 0

输出 => 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

输出 => 1