You can get official oracle instruction to remove java from macOS here
In your macOS terminal type this one by one
sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane sudo rm -fr ~/Library/Application\ Support/Oracle/Java
After that you can navigate to specific version of java that you intend to delete by using the following command:
ls in your terminal to list down all the Java Virtual Machine Folders.
Finally add the version number you want to delete like this
sudo rm -rf jdk-10.0.1.jdk
Instead of jdk-10.0.1.jdk you can give any version number which are listed down in your above mentioned folder.