有没有办法找出一个ArrayList有多少个列表?
ArrayList<ArrayList<Integer>> myList = new ArrayList<ArrayList<Integer>>(); List<Integer> myOtherList = new LinkedList<Integer>();
发布于 2012-12-02 08:04:50
与任何列表一样,您可以使用List#size()找出它包含了多少对象。
int size = myList.size(); // amount of sublists that myList holds发布于 2012-12-02 08:12:30
@Vulcan的响应将得到列表的大小。如果只想要列表中包含的ArrayLists,则需要使用instanceof检查元素类型,并以这种方式递增计数:
int listcount = 0;
for (Object e : list) {
if (e instanceof ArrayList) listcount++;
}https://stackoverflow.com/questions/13665073
复制相似问题