Simplifying reverse function in Stringfunctions class
swapy opened this issue · 1 comments
swapy commented
public static final String reverseWithStringBuilder(String string) {
StringBuilder builder = new StringBuilder();
for (int i = (string.length() - 1); i >= 0; i--) {
builder.append(string.charAt(i));
}
return builder.toString();
}
can we simplify this code to
public static final String reverseWithStringBuilder2(String string) {
StringBuilder builder = new StringBuilder(string);
builder.reverse();
return builder.toString();
}
swapy commented
Sorry for that, closing as reverseWithStringBuilderBuiltinMethod is already present.