import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
public class Delete
{
public static void main(String[] args)
{
List<List<String>> list = new ArrayList<>();
list.add(List.of("A","B","C","R"));
list.add(List.of("E","F","G","F"));
list.add(List.of("A","B","C","D"));
System.out.println(list.stream().distinct().count());
Map<String, Long> countMapOfColumn = list.stream()
.filter(innerList -> innerList.size() >= 3)
.map(innerList -> innerList.get(3 - 1))
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
System.out.println(countMapOfColumn.keySet());
}
}
I want to find out the unique element of column 3 which are "C","G" and there are 2 unique element in column 3.
This can be done using loop but I can't use loop. Using java stream there may be a solution.
In addition, how can I get count of rows having "A","B" in column 1,2 at a time and in general for N columns?