public static < T > List < T > toList ( Iterator < T > self ) { List < T > answer = new ArrayList < T > ( ) ; while ( self . hasNext ( ) ) { answer . add ( self . next ( ) ) ; } return answer ; }
Convert an iterator to a List . The iterator will become exhausted of elements after making this conversion .