Can anyone help me write me a Java method that takes a substring of a string, reverses it and prints the outcome?
I'm guessing a StringBuilder is better than String but my issue is StringBuilder.substring() returns a String. To continue using StringBuilder I'd need to create a new StringBuilder object to do the StringBuilder.reverse() part.
Anyone a better solution to this?
public static void main(String[] args) {
StringBuilder sb = new StringBuilder("abcdefgh");
sb = new StringBuilder(sb.subSequence(2, 5));
sb.reverse();
System.out.println(sb.toString());
}