title: is it possible to specify the length when generate data using md5 in java
body: <p>I want to generate the app id in java 11 code, this is the code I am using right now:</p>
  <pre><code>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(&quot;MD5&quot;);
              byte[] array = md.digest(md5.getBytes());
              StringBuffer sb = new StringBuffer();
              for (int i = 0; i &lt; array.length; ++i) {
                  sb.append(Integer.toHexString((array[i] &amp; 0xFF) | 0x100).substring(1,3));
              }
              return sb.toString();
          } catch (java.security.NoSuchAlgorithmException e) {
          }
          return null;
      }
  }
  </code></pre>
  <p>The problem is that the appId is a little bit too long like this <code>9b8388c95d1598fbe9fbcffd75c518eb</code>. Is it possible to make it more shorter like this <code>efd678efh567hg6787</code> and keep it unique? I can using the substring, but I am not sure it is a good way to do like this.</p>