Java String Leading Character addLeadingSlash(String path)

Here you can find the source of addLeadingSlash(String path)

Description

Ensures the given chunk path starts with a leading slash

License

Apache License

Parameter

Parameter Description
path the path

Return

the path with leading slash

Declaration

public static String addLeadingSlash(String path) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from www .  j  a v  a 2s  . c  o m*/
     * Ensures the given chunk path starts with a leading slash
     * @param path the path
     * @return the path with leading slash
     */
    public static String addLeadingSlash(String path) {
        if (path == null) {
            return null;
        }
        if (!path.isEmpty() && path.charAt(0) == '/') {
            return path;
        }
        return "/" + path;
    }
}

Related

  1. addLeadingCharacter(String s, char c, int len)
  2. addLeadingCharacter(String s, char c, int len)
  3. addLeadingSlash(String fileName)
  4. addLeadingSlash(String fileName)
  5. addLeadingSlash(String path)
  6. addLeadingSlash(String string)
  7. addLeadingSpace(String s, int len)
  8. addLeadingSpace(String s, int len)