toArray method for collections