private Service [ ] toArray ( List < Service > services ) { if ( services == null ) { return new Service [ 0 ] ; } if ( services instanceof ArrayList ) { return ( ( ArrayList < Service > ) services ) . toArray ( new Service [ services . size ( ) ] ) ; } else { Service [ ] ret = new Service [ services . size ( ) ] ; for ( int i = 0 ; i < services . size ( ) ; i ++ ) { ret [ i ] = services . get ( i ) ; } return ret ; } }
convert list to array never returns null .