Skip to content
Sharp

API Evolution · interview question

How can you convert a legacy java.util.Date object to a java.time.Instant in modern Java?

Multiple choiceHardchapter-12-curatedpremiumapi-evolutionmodern-date-and-time
Choose one answer
Answer and explanation

Correct answer

A. Date.toInstant()

Why

The toInstant() method on a java.util.Date object is used to convert it to a java.time.Instant. This conversion allows you to use the more modern, immutable, and thread-safe java.time API.

Test yourself on API Evolution

A free test with instant, explained results. No account needed.

Start free test
All API Evolution questions →