I have a list of list and i want to return the list that have the min size using java Stream.
Here what i tried:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Example {
public static void main( String[] args ) {
ArrayList<Integer> list1 = new ArrayList<>();
list1.add(0);list1.add(2);list1.add(3);
ArrayList<Integer> list2 = new ArrayList<>();
list2.add(0);list2.add(2);list2.add(3);list2.add(4);
System.out.println( getTheMinList(list1,list2).size());
}
public static ArrayList<Integer> getTheMinList(ArrayList<Integer>... lists) {
return Arrays.stream(lists)
.map(list->list.size())
/*here i stoped*/
;
}
}
The program should print 3
because the first list has the minimum size.
Note that I can't change the signature of the getTheMinList(). Could anyone please give me a hint?