Here you can find the source of join(List
public static String join(List<String> paths)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { public static String join(List<String> paths) { if (paths == null || paths.isEmpty()) { return null; }/* w ww . j ava2 s .c o m*/ StringBuilder sb = new StringBuilder(); for (int i = 0; i < paths.size(); i++) { if (i == 0) { sb.append(trimTrailingSlash(paths.get(i))); } else { sb.append("/").append(trimSlash(paths.get(i))); } } return sb.toString(); } public static String join(String... paths) { if (paths == null || paths.length == 0) { return null; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < paths.length; i++) { if (i == 0) { sb.append(trimTrailingSlash(paths[i])); } else { sb.append("/"); sb.append(trimSlash(paths[i])); } } return sb.toString(); } public static String join(String[] paths, int offset, int length) { if (paths == null || paths.length == 0 || offset >= paths.length) { return null; } int end = offset + length; if (end > paths.length) { end = paths.length; } StringBuilder sb = new StringBuilder(); for (int i = offset; i < end; i++) { if (i == 0) { sb.append(trimTrailingSlash(paths[i])); } else { sb.append("/").append(trimSlash(paths[i])); } } return sb.toString(); } public static String trimTrailingSlash(String path) { if (path == null || path.isEmpty()) { return path; } while (path.endsWith("/")) { path = path.substring(0, path.length() - 1); } return path; } public static String trimSlash(String path) { return trimTrailingSlash(trimLeadingSlash(path)); } public static String trimLeadingSlash(String path) { if (path == null || path.isEmpty()) { return path; } while (path.startsWith("/")) { path = path.substring(1); } return path; } }