Can java.lang.String.format(String str, String str1)
be used for adding prefix of a particular character.
I could do this for a number like:
You can do as below if you really want to use String.format
,
String sendID = "AABB";
String.format("%32s", sendID ).replace(' ', '0')
Other than String.format
you can find many solutions here.
Edit: Thanks for Brian to point of the issue. The above wont work for input with spaces. You can try as below. But I wont suggest the below operation as it has too many string operation.
String sendID = "AA BB";
String suffix = String.format("%32s", "").replace(' ', '0') + sendID;
sendID = suffix.substring(sendID.length());
You can also try using StringUtils.leftPad
StringUtils.leftPad(sendID, 32 - sendID.length(), '0');