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

StringaddLeadingCharacter(String s, char c, int len)
Adds specified leading characters to the specified length.
if (s != null) {
    StringBuffer sb = new StringBuffer();
    int count = len - s.length();
    for (int i = 0; i < count; i++) {
        sb.append(c);
    sb.append(s);
    return sb.toString();
...
StringaddLeadingCharacter(String s, char c, int len)
Adds specified leading characters to the specified length.
while (s != null && s.length() < len) {
    s = c + s;
return s;
StringaddLeadingSlash(String fileName)
Adds the leading slash if needed on the beginning of a filename.
if (fileName.startsWith("/")) {
    return fileName;
return "/" + fileName;
StringaddLeadingSlash(String fileName)
add Leading Slash
return addLeadingUnixSlash(fileName);
StringaddLeadingSlash(String path)
Ensures the given chunk path starts with a leading slash
if (path == null) {
    return null;
if (!path.isEmpty() && path.charAt(0) == '/') {
    return path;
return "/" + path;
StringaddLeadingSlash(String path)
add Leading Slash
return path.startsWith("/") ? path : "/" + path;
StringaddLeadingSlash(String string)
add Leading Slash
if (string == null)
    throw new NullPointerException("string must not be null");
if (string.startsWith("/"))
    return string;
return "/" + string;
StringaddLeadingSpace(String s, int len)
Adds leading spaces to the given string to the specified length.
return addLeadingCharacter(s, ' ', len);
StringaddLeadingSpace(String s, int len)
Adds leading spaces to the given String to the specified length.
return addLeadingCharacter(s, ' ', len);
StringaddLeadingUnixSlash(String fileName)
Adds the leading slash if needed on the beginning of a filename.
if (fileName.startsWith("/")) {
    return fileName;
return "/" + fileName;