tk.hongkailiu.test.app.string.StringUtil Maven / Gradle / Ivy
The newest version!
package tk.hongkailiu.test.app.string;
public class StringUtil {
public static String reverseRecursion(String str) {
if (str == null || str.length() == 1) {
return str;
}
return reverseRecursion(str.substring(1)) + str.charAt(0);
}
public static String reverseLoop(String str) {
if (str == null || str.length() == 1) {
return null;
}
char[] chars = str.toCharArray();
StringBuilder sb = new StringBuilder();
for (int i = chars.length; i > 0; i--) {
sb.append(chars[i - 1]);
}
return sb.toString();
}
public static String reverseApi(String str) {
if (str == null) {
return null;
}
return new StringBuilder(str).reverse().toString();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy