Java SE 8 Programmer II — Question 37

Given the code fragments:
class TechName {
String techName;
TechName (String techName) {
this.techName=techName;
}
}
and
List<TechName> tech = Arrays.asList (
new TechName("Java-"),
new TechName("Oracle DB-"),
new TechName("J2EE-")
);
Stream<TechName> stre = tech.stream();
//line n1
Which should be inserted at line n1 to print Java-Oracle DB-J2EE-?

Answer options

Correct answer: B

Explanation

The correct answer is B because it specifically maps each TechName object to its techName string before printing, resulting in the desired output. Option A prints the TechName objects directly, which would not yield the correct format. Option C does not extract the techName and would not give the correct output either, while option D also prints the objects directly without mapping to the strings.