IteratorUtils { public static <T> List<T> toList(Iterator<T> iterator) { List<T> list = new ArrayList<>(); while (iterator.hasNext()) { list.add(iterator.next()); } return list; } private  IteratorUtils(); static List<T> toList(Iterator<T> iterator);  }
@Test public void testToList() { Set<String> set = new LinkedHashSet<>(); set.add("A"); set.add("B"); List<String> result = IteratorUtils.toList(set.iterator()); assertNotNull(result); assertEquals(2, result.size()); assertEquals("A", result.get(0)); }