You can use Class MessageDigest. It is hash functions which takes an arbitrary-sized data and the output is a fixed-length hash value.
This class contains a method getInstance which takes in the name of the algorithm requested and returns a Message Digest object that implements the specified algorithm. It can throw an exception NoSuchAlgorithmException, if the specified algorithm is not there in the provider.
So, if you want the MD5 hash, give MD5 as parameter in getInstance function of Class MessageDigest.