[Java lista] Fwd: Array join
Peter Verhas
peter at verhas.com
2009. Aug. 22., Szo, 20:46:39 CEST
Ezt éppen most követtem el (még nincs kidebuggolva)
public static String join(Collection s, String delimiter) {
StringBuffer buffer = new StringBuffer();
Iterator iter = s.iterator();
while (iter.hasNext()) {
buffer.append(iter.next());
if (iter.hasNext()) {
buffer.append(delimiter);
}
}
return buffer.toString();
}
private String absolute(String currentPath, String relativePath) {
if (relativePath.startsWith("/")) {
return relativePath;
}
String fullPath = currentPath + "/" + relativePath;
fullPath = fullPath.replaceAll("//", "/");
ArrayList<String> pathParts =
new ArrayList(Arrays.asList(fullPath.split("/")));
int i = 0;
while (i < pathParts.size()) {
if (pathParts.get(i).equals("..")) {
pathParts.remove(i);
if (i > 0) {
pathParts.remove(i - 1);
}
} else {
i++;
}
}
fullPath = join(pathParts, "/");
return fullPath;
}
További információk a(z) Javalist levelezőlistáról