@ SuppressWarnings ( "unchecked" ) public static < E > E [ ] filter ( E [ ] elems , Filter < E > filter ) { List < E > filtered = new ArrayList < E > ( ) ; for ( E elem : elems ) { if ( filter . accept ( elem ) ) { filtered . add ( elem ) ; } } return ( filtered . toArray ( ( E [ ] ) Array . newInstance ( elems . getClass ( ) . getComponentType ( ) , filtered . size ( ) ) ) ) ; }
Applies the given filter to each of the given elems and returns the list of elems that were accepted . The runtime type of the returned array is the same as the passed in array .