private static < T > T [ ] removeNull ( T [ ] items ) { int count = 0 ; for ( int i = 0 ; i != items . length ; ++ i ) { if ( items [ i ] == null ) { count = count + 1 ; } } if ( count == 0 ) { return items ; } else { T [ ] rs = java . util . Arrays . copyOf ( items , items . length - count ) ; for ( int i = 0 , j = 0 ; i != items . length ; ++ i ) { T item = items [ i ] ; if ( item != null ) { rs [ j ++ ] = item ; } } return rs ; } }
Create exact copy of a given array but with evey null element removed .