Here you can find the source of makePath(String... elements)
Parameter | Description |
---|---|
elements | The elements to create a path with |
public static String makePath(String... elements)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.util.Arrays; public class Main { /**/*ww w .j a va 2 s. c om*/ * Construct a file path from the given elements, i.e. separate the given elements by the file separator. * * @param elements The elements to create a path with * * @return The created path */ public static String makePath(String... elements) { return join(File.separator, elements); } /** * Join a list of elements into a single string with the specified delimiter. * * @param delimiter The delimiter to use * @param elements The elements to join * * @return A new String that is composed of the elements separated by the delimiter */ public static String join(String delimiter, Iterable<String> elements) { if (delimiter == null) { delimiter = ""; } StringBuilder sb = new StringBuilder(); for (String element : elements) { if (!isEmpty(element)) { // Add the separator if it isn't the first element if (sb.length() > 0) { sb.append(delimiter); } sb.append(element); } } return sb.toString(); } /** * Join a list of elements into a single string with the specified delimiter. * * @param delimiter The delimiter to use * @param elements The elements to join * * @return A new String that is composed of the elements separated by the delimiter */ public static String join(String delimiter, String... elements) { return join(delimiter, Arrays.asList(elements)); } /** * Null-safe method for checking whether a string is empty. Note that the string * is trimmed, so this method also considers a string with whitespace as empty. * * @param str The string to verify * * @return True if the string is empty, false otherwise */ public static boolean isEmpty(String str) { return str == null || str.trim().isEmpty(); } }