Hi,
Mmm. I cant seem to find the class StringUtils and the method bytesToHex in the JDK docs.
If I look at your code I think you’re converting a byte/char array into a hexadecimal string minus
the last 4 bytes/chars. One byte/char would correspond to 2 digits in the resulting string.
So limiting the length to 8 would only work if the original userId would be exactly 8 bytes
-> abcdefgh minus 4 -> abcd -> 61626364
If it would be, lets say 6 bytes the result would be :
-> abcdef minus 4 -> ab -> 6162
Oops 
If you would want to limit the length of an array why not use System.arraycopy :
char[] src="42:life universe everything".toCharArray();
char[] dst=new char[8];
System.arraycopy(src,0,dst,0,dst.length);
myId=new String(dst);
or…
myId=new String(userId,0,userId.length>8?8:userId.length);
Good luck !
Erik