77import java .util .*;
88import java .util .stream .*;
99
10- import static java .util .stream .Collectors .toList ;
11- import static java .util .stream .Collectors .toSet ;
10+ import static java .util .stream .Collectors .*;
1211import static org .hamcrest .CoreMatchers .equalTo ;
1312import static org .hamcrest .core .IsNot .not ;
1413import static org .junit .Assert .*;
@@ -22,7 +21,7 @@ public void setUp() {
2221 List <String > xs = LongStream .range (0 , 16 )
2322 .boxed ()
2423 .map (Long ::toHexString )
25- .collect (toList ( ));
24+ .collect (toCollection ( ArrayList :: new ));
2625 stringsToSearch = new ArrayList <>(xs );
2726 stringsToSearch .addAll (xs );
2827 }
@@ -92,7 +91,7 @@ public void givenPredicate_whenIterateArrayList_thenFindAllElementsSatisfyingPre
9291 List <String > result = stringsToSearch
9392 .stream ()
9493 .filter (matchingStrings ::contains )
95- .collect (toList ( ));
94+ .collect (toCollection ( ArrayList :: new ));
9695
9796 assertEquals (6 , result .size ());
9897 }
@@ -107,7 +106,7 @@ public void givenSortedArray_whenUseBinarySearch_thenFindElement() {
107106
108107 @ Test
109108 public void givenIndex_whenRemove_thenCorrectElementRemoved () {
110- List <Integer > xs = IntStream .range (0 , 10 ).boxed ().collect (toList ( ));
109+ List <Integer > xs = IntStream .range (0 , 10 ).boxed ().collect (toCollection ( ArrayList :: new ));
111110 Collections .reverse (xs );
112111
113112 xs .remove (0 );
@@ -119,7 +118,7 @@ public void givenIndex_whenRemove_thenCorrectElementRemoved() {
119118
120119 @ Test
121120 public void givenListIterator_whenReverseTraversal_thenRetrieveElementsInOppositeOrder () {
122- List <Integer > xs = IntStream .range (0 , 10 ).boxed ().collect (toList ( ));
121+ List <Integer > xs = IntStream .range (0 , 10 ).boxed ().collect (toCollection ( ArrayList :: new ));
123122 ListIterator <Integer > it = xs .listIterator (xs .size ());
124123 List <Integer > result = new ArrayList <>(xs .size ());
125124 while (it .hasPrevious ()) {
0 commit comments