public class Welcome { public static void main(String[] args) { Stream words = Pattern.compile(" ").splitAsStream("Hadoop Exam .com Quick Techie .com"); System.out.println(words.map(word -> word.length()).sum()); } } 1. Code will give compile time error.
4. Code will run and compile perfectly and print 29
Correct Answer : Get Lastest Questions and Answer : Explanation: As we have used map function using lambda expression which return as Stream. And you know that sum() method is not available on it. Hence, you will get compile time error. To solve this issue we should have used mapToInt() method as below.
public class Welcome { public static void main(String args[]) { maxValue(IntStream.of(1,2,3,4,5)); // //n1 }
public static void maxValue(IntStream values) { OptionalInt max = values.max(); //n2 if (max.ifPresent()) { //n3 System.out.print(max.getAsInt()); } } } 1. Code will give compile time error.
Correct Answer : Get Lastest Questions and Answer : Explanation: : Look carefully, its illusion question. You check method at line n3, it is not isPresent it is ifPresent() method. And ifPresent() signature is wrong. Hence, you will get compile time error. Change ifPresent to isPresent you will get 5 as output.
Question : You have been given below code, what is the expected behavior?
4. Code will run perfectly and print "Hadoop Exam .com NULL"
Correct Answer : Get Lastest Questions and Answer : Explanation: There are following important point to understand ofNullable() : Returns an Optional describing the specified value, if non-null, otherwise returns an empty Optional. orElse() : Return the value if present, otherwise return other.
3. It will throw error : java.nio.file.InvalidPathException: UNC path is missing sharename: 4. java.nio.file.InvalidPathException: UNC path is missing sharename: //hadoop.txt/