CARVIEW |
Java Streams CIP
Question 2
What does the code do,
class HelloWorld {
public static void main(String[] args) {
List<Integer> l = Array.list( 5, 10, 12, 30, 8, 7 );
l.stream()
.filter( x -> x % 2 == 0 )
.filter( x > 10 )
.forEach( System.out::println );
}
}
Prints all the numbers in the list l
Prints all the even numbers in the list l
Prints all the even numbers in the list l which are greater than 10
None of these
Question 3
Do streams have their own storage?
Yes, streams have there own storage
They create storage dynamically
They create an abstraction over the given source
None of the above
Question 4
Can parallel streams be created?
Yes, they use multiple resources of the system if needed and run parallelly
No, they cannot be created
They can be created but they do not run parallelly
None of these
Question 5
What is the benefit(s) of using streams?
Makes the code readable
Makes the code short
Makes the code efficient
None of these
Question 6
Methods provided by BaseStream are?
Parallel()
Sequential()
Unordered()
None of these
Question 7
Sub-interface of BaseStream are?
IntStream
DoubleStream
LongStream
Stream<T>
All of the above
Question 8
What is the output of the code,
class GFG{
public static void main(String[] args) {
int arr[] = { 30, 20, 50 };
int sum = Arrays.stream(arr)
.sum();
System.out.println(sum);
}
}
80
100
20
30
Question 9
What is the output of the code?
class HelloWorld {
public static void main(String[] args) {
int arr[] = { 30, 20, 10 };
int temp = Arrays.stream(arr)
.average();
.getDouble();
System.out.println(temp);
}
}
20
60
20.0
60.0
Question 10
What is the output of the code,
class HelloWorld {
public static void main(String[] args) {
Stream.iterate(1, x->x+1 )
.filter( x->x.toString().contains("5"))
.limit(10)
.forEach(System.out::println);
}
}
5, 10, 15, 20, 25, 30, 35, 40, 45, 50
5, 15, 25, 35, 45, 50, 51, 52, 53, 54
1, 6, 11, 16, 21, 26, 31, 36, 41, 46
None of these
There are 10 questions to complete.