commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Melzer, Steven" <>
Subject collections size
Date Fri, 19 Mar 2004 18:01:19 GMT

i am using the commons collections api and am very impressed with it.  i am largely using
it to iterate over an arbitrary list, so i mostly use the IteratorUtils class.

one method i needed for a project does not seem to be available though, size(), that would
return the size of an arbitary list.

so i wrote the following:
	public static int size(Object list) throws IllegalArgumentException {
		int i = 0;
		if (list instanceof Collection) {
			i = ((Collection)list).size();
		} else if (list instanceof Map) {
			i = ((Map)list).size();
		} else {
			i = Array.getLength(list);
		return i;

thought it would be nice to include this functionality in an upcoming commons collection release.


Learn more about Paymentech's payment processing services at
THIS MESSAGE IS CONFIDENTIAL.  This e-mail message and any attachments are proprietary and
confidential information intended only for the use of the recipient(s) named above.  If you
are not the intended recipient, you may not print, distribute, or copy this message or any
attachments.  If you have received this communication in error, please notify the sender by
return e-mail and delete this message and any attachments from your computer.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message