How to know JDK version from within Java code
Relying on the java.version string for anything else than showing to a human is fragile and will break if running on another Java implementation.
The only reliable way programatically is to use reflection to carefully ask if a given facility is available, and then select the appropriate code accordingly.