@ SuppressWarnings ( "PMD.UnusedLocalVariable" ) public static < T > int size ( Iterable < T > iter ) { if ( iter instanceof ArrayTagSet ) { return ( ( ArrayTagSet ) iter ) . size ( ) ; } else if ( iter instanceof Collection < ? > ) { return ( ( Collection < ? > ) iter ) . size ( ) ; } else { int size = 0 ; for ( T v : iter ) { ++ size ; } return size ; } }
Returns the size of an iterable . This method should only be used with fixed size collections . It will attempt to find an efficient method to get the size before falling back to a traversal of the iterable .