com.almondtools.util.text.StringUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stringsandchars Show documentation
Show all versions of stringsandchars Show documentation
Searching and Matching Strings and Chars with efficient algorithms.
The newest version!
package com.almondtools.util.text;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
public final class StringUtils {
private StringUtils() {
}
public static String reverse(String word) {
char[] chars = word.toCharArray();
int size = word.length();
for (int li = 0, ri = size - 1; li < ri; li++,ri--) {
char swap = chars[li];
chars[li] = chars[ri];
chars[ri] = swap;
}
return new String(chars);
}
public static String join(Iterable> objects) {
Iterator> iterator = objects.iterator();
if (!iterator.hasNext()) {
return "";
}
StringBuilder buffer = new StringBuilder(iterator.next().toString());
while (iterator.hasNext()) {
buffer.append(iterator.next().toString());
}
return buffer.toString();
}
public static String join(Iterable> objects, char c) {
Iterator> iterator = objects.iterator();
if (!iterator.hasNext()) {
return "";
}
StringBuilder buffer = new StringBuilder(iterator.next().toString());
while (iterator.hasNext()) {
buffer.append(c);
buffer.append(iterator.next().toString());
}
return buffer.toString();
}
public static String join(Iterable> objects, String s) {
Iterator> iterator = objects.iterator();
if (!iterator.hasNext()) {
return "";
}
StringBuilder buffer = new StringBuilder(iterator.next().toString());
while (iterator.hasNext()) {
buffer.append(s);
buffer.append(iterator.next().toString());
}
return buffer.toString();
}
public static List toCharArray(Collection patterns) {
List charpatterns = new ArrayList(patterns.size());
for (String pattern : patterns) {
charpatterns.add(pattern.toCharArray());
}
return charpatterns;
}
}