Now can you convert that code into Java with the same function?