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?
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())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With