1. What is the output?
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
Arrays.asList(new String[]{"red","blue","orange","green","pink"})
.stream().filter(s->s.contains("e")).forEach(System.out::println);
}
}
a) red blue orange green b) blue green orange pink red c) red blue orange green pink d) compile error
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is a) red blue orange green
Correct! red blue orange green
2. What is the output?
String[][] names = {
{"A", "B", "C"}, {"M", "N", "O"}, {"X", "Y"}
};
Arrays.asList(names).stream()
.forEach((a)->{Arrays.asList(a)
.stream().forEach(System.out::print);});
a) AMNOBXYC b) AMXBNYCO c) ABCMNOXY d) No output displayed
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is c) ABCMNOXY
The outer forEach operates on each inner array, where another stream is created to print each inner element.
Correct! ABCMNOXY
The outer forEach operates on each inner array, where another stream is created to print each inner element.
3. What is the output?
String str="none", s;
if(str.equals("none"))
s = str+10;
else
s = str+100;
System.out.print(s);
a) none100 b) none10 c) compile error s is not initialized d) compile error cannot add int to String
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is b)none10 s is initialized in if or else
Correct! none10 s is initialized in if or else
4. What is the output?
String[] arr = { "red", "blue", null, "pink", null };
List<String> arrL = Arrays.asList(arr);
arrL.stream().forEach(System.out::print);
a) Compile error b) bluenullpinkred c) redbluenullpink d) redbluenullpinknull
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is d) redbluenullpinknull List accepts null more than once
Correct! redbluenullpinknull List accepts null more than once
5. What is the output?
public interface Finder {
String find(T t);
}
public class FinderTest {
public static void main(String[] args) {
Finder finder = e -> e.getName()+":"+e.getAge();
System.out.println(finder.find(new Emp("Geeta", 25)));
}
}
public class Emp {
private String name;
private int age;
public Emp(String name, int age) {
this.name = name;
this.age = age;
}
public int getAge() {
return age;
}
public String getName() {
return name;
}
}
a) Compile error b) Geeta:0 c) null:0 d) Geeta:25
Wrong! Try again..
Wrong Again! Try one more chance.
Wrong! The correct answer is d) Geeta:25
Correct! Geeta:25
6. Which are TRUE with respect to Built-in Functional Interfaces?
A. A Supplier takes no arguments and returns a result
B. A Consumer takes an argument, but returns no result
C. The method in Consumer is : accept(T)
D. A BiPredicate takes two arguments , and returns boolean
a) A, B, C b) A, C, D c) B, C, D d) All of them
Wrong! Try again.
Wrong Again! Try one more chance.
Wrong! The correct answer is d)All of them
Correct! All of them
7. . The following is an implementation of which Functional Interface?
()-> "Hello guys"
a) Predicate b) Consumer c) Supplier d) None of the above