What does the following output?
import java.util.ArrayList; import java.util.List; public class Main { public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("Austin"); list.add("Boston"); list.add("San Francisco"); long c = list.stream().filter(a -> a.length() > 10).count(); System.out.println(c + " " + list.size()); }/*from ww w .j av a 2 s .c o m*/ }
B.
The stream pipeline is correct and filters all values out that are 10 characters or smaller.
Only San Francisco is long enough, so c is 1.
The stream()
call creates a new object, so stream operations do not affect the original list.
Since the original list is still 3 elements, Option B is correct.