public static < T > Collection < T > collectIterator ( Iterator < T > iterator , Collection < T > targetCollection ) { while ( iterator . hasNext ( ) ) { targetCollection . add ( iterator . next ( ) ) ; } return targetCollection ; }
Extracts all elements from an iterator usually created from a filterator and adds them into the target collection returning that collection as the result .