Capture the new list
Your code creates a new list each time through the for loop. But the new list is immediately lost, headed for garbage collection. You neglected to capture a reference to that newly-created list.
So, the solution is: Replace the old list stored as an element in the outer list with the new list. Wrap your stream line with bigList.set( i , … ).
public static List< List< String > > bigList = new ArrayList<>(); // A list of lists of strings.
…
for (int i = 0; i < bigList.size(); i++) {
bigList.set(
i , // Index of outer list, where the new list should go.
bigList
.get(i)
.stream()
.map( str -> new LinkedHashSet<>( Arrays.asList( str.split( "," ) ) ) )
.distinct()
.map( set -> set.stream().collect( Collectors.joining( "," ) ) )
.collect( Collectors.toList() ) // Produce a new list. Stored in place of the old list.
) ;
}
For clarity, break the code into separate lines.
public static List< List< String > > bigList = new ArrayList<>(); // A list of lists of strings.
…
for (int i = 0; i < bigList.size(); i++) {
List< String > oldList = bigList.get( i ) ;
List< String > newList =
oldList
.stream()
.map( str -> new LinkedHashSet<>( Arrays.asList( str.split( "," ) ) ) )
.distinct()
.map( set -> set.stream().collect( Collectors.joining( "," ) ) )
.collect( Collectors.toList() ) // Produce a new list. Stored in place of the old list.
) ;
bigList.set( i , newList ) ; // Replace the old list with the newly-created list.
}
.collect(Collectors.toList())to anything. So you are constructing a new list, which is just immediately thrown away.bigList.set( i , … )to replace the old list with the new list.forloop will not run at all; you dobigList = new ArrayList<>()and you loop oni < bigList.size()— well, bigList.size() is zero so there will be no iterations.get, followed by callingset, it’s much simpler to usebigList.replaceAll(list -> list.stream()….collect(Collectors.toList()));Alternatively, the OP could truly remove the duplicates from the lists, instead of creating new lists.