Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count items in ArrayList

Tags:

android

How can I count the items in an ArrayList?

ArrayList list1= new ArrayList();
list1.add("a"); 
list1.add("b"); 
list1.add("c"); 
list1.add("d"); 
list1.add("e"); 
...........
result.setMessage(list1.size()); // = 5
...........

It does not work. Where is the error?

like image 898
user1198014 Avatar asked Oct 20 '25 07:10

user1198014


1 Answers

Presumably result is an AlertDialog, if so, then you are calling result.setMessage(int) which expects a resource ID. What you want is to cast the size() value (an int) to a String, e.g. result.setMessage("" + list1.size())

like image 84
dmon Avatar answered Oct 21 '25 22:10

dmon