'is it possible to specify the length when generate data using md5 in java

I want to generate the app id in java 11 code, this is the code I am using right now:

import java.util.UUID;

public class AppStarter {

    public static void main(String[] args) {
        String uuid= UUID.randomUUID().toString();
        System.out.println(uuid);
        String appId = MD5(uuid);
        System.out.println(appId);
    }

    public static String MD5(String md5) {
        try {
            java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
            byte[] array = md.digest(md5.getBytes());
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < array.length; ++i) {
                sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1,3));
            }
            return sb.toString();
        } catch (java.security.NoSuchAlgorithmException e) {
        }
        return null;
    }
}

The problem is that the appId is a little bit too long like this 9b8388c95d1598fbe9fbcffd75c518eb. Is it possible to make it more shorter like this efd678efh567hg6787 and keep it unique? I can using the substring, but I am not sure it is a good way to do like this.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source