Author name: admin

Which method can be used to check if all elements in a stream match a given predicate?

Which method can be used to check if all elements in a stream match a given predicate? a) allMatch() b) anyMatch() c) noneMatch() d) matchesAll() Answer: a) allMatch() Explanation: The allMatch() method in the Stream API is used to check if all elements in a stream match a given predicate. This method is a terminal

Which method can be used to check if all elements in a stream match a given predicate? Read More »

Which of the following is a short-circuiting terminal operation in the Stream API?

Which of the following is a short-circuiting terminal operation in the Stream API? a) forEach() b) map() c) filter() d) anyMatch() Answer: d) anyMatch() Explanation: The anyMatch() method is a short-circuiting terminal operation in the Stream API that returns true if any element in the stream matches the given predicate. This method is particularly useful

Which of the following is a short-circuiting terminal operation in the Stream API? Read More »

Which method is used to collect the results of a stream operation into a List?

Which method is used to collect the results of a stream operation into a List? a) toList() b) collect() c) gather() d) accumulate() Answer: b) collect() Explanation: The collect() method is used to collect the results of a stream operation into a List, Set, or other collection types. It is one of the most commonly

Which method is used to collect the results of a stream operation into a List? Read More »

What is the difference between a stream() and a parallelStream() in Java?

What is the difference between a stream() and a parallelStream() in Java? a) stream() is faster than parallelStream() b) parallelStream() processes elements in parallel c) stream() uses more memory d) parallelStream() is only for arrays Answer: b) parallelStream() processes elements in parallel Explanation: The primary difference between stream() and parallelStream() in Java lies in how

What is the difference between a stream() and a parallelStream() in Java? Read More »

Which of the following is NOT a characteristic of streams in Java?

Which of the following is NOT a characteristic of streams in Java? a) Streams are immutable b) Streams can be parallel c) Streams store elements d) Streams can be infinite Answer: c) Streams store elements Explanation: Streams in Java do not store elements; instead, they provide a pipeline for processing data. Unlike collections such as

Which of the following is NOT a characteristic of streams in Java? Read More »

Which method is used to unmarshal an XML document to a Java object using JAXB?

Which method is used to unmarshal an XML document to a Java object using JAXB? A) unmarshal() B) deserialize() C) convertToObject() D) readFromXML() Answer: A) unmarshal() Explanation: The unmarshal() method in JAXB is used to convert an XML document to a Java object. This process is known as unmarshalling. The unmarshal() method reads the XML

Which method is used to unmarshal an XML document to a Java object using JAXB? Read More »

Scroll to Top