To hash a string using SHA-256 in Java, you can use the MessageDigest class from the java.security package.