Java Utililty Methods String Leading Character

List of utility methods to do String Leading Character

Description

The list of methods to do String Leading Character are organized into topic(s).

Method

byte[]addLeadingZero(byte[] value)
add Leading Zero
byte[] result = new byte[value.length + 1];
result[0] = 0;
System.arraycopy(value, 0, result, 1, value.length);
return result;
StringaddLeadingZero(final int value)
add Leading Zero
if (value < 10) {
    return "0" + value; 
} else {
    return String.valueOf(value);
StringaddLeadingZero(String aString, int aAmountOfZeros)
add Leading Zero
final int stringLength = aString.length();
if (stringLength < aAmountOfZeros) {
    for (int i = 0, l = aAmountOfZeros - stringLength; i < l; ++i) {
        aString = "0" + aString;
return aString;
StringaddLeadingZeroesTo16BitBinaryString(String binaryValue)
add Leading Zeroes To Bit Binary String
int length = binaryValue.length();
while (binaryValue.length() < 16) {
    binaryValue = "0" + binaryValue;
return binaryValue;
StringaddLeadingZeros(Object number, int places)
add Leading Zeros
if (number == null)
    return null;
if (number instanceof String)
    try {
        Double.valueOf((String) number);
    } catch (Throwable t) {
        throw new IllegalArgumentException(
                "addLeadingZeros, problem with string value " + number + ": " + t.getCause());
...
StringaddLeadingZeros(String deweyCallNum)
adds leading zeros to a dewey call number, when they're missing.
String result = deweyCallNum;
String b4Cutter = getPortionBeforeCutter(deweyCallNum);
String b4dec = null;
int decIx = b4Cutter.indexOf(".");
if (decIx >= 0)
    b4dec = deweyCallNum.substring(0, decIx).trim();
else
    b4dec = b4Cutter.trim();
...
StringaddLeadingZeros(String number, int maxDigits)
adds some leading '0' to the sting until the length maxDigits is reached
StringBuilder result = new StringBuilder(number);
while (result.length() < maxDigits) {
    result.insert(0, "0");
return result.toString();
StringaddLeadingZeros(String s, int nZeros)
Prepends nZeros zeros to the given string and returns the resulting string.
char[] zeros = new char[nZeros];
for (int i = 0; i < zeros.length; i++)
    zeros[i] = '0';
return String.valueOf(zeros) + s;
StringaddLeadingZeros(String str)
add Leading Zeros
String nStr = str;
while (nStr.length() < 15) {
    nStr = "0" + nStr;
return nStr;
StringaddLeadingZerosToNumber(long number, int length)
add Leading Zeros To Number
if (length <= ((int) Math.log10(number) + 1))
    return String.valueOf(number);
return String.format("%0" + length + "d", number);