sS reversedSubstring(S s, int x, int y) { if (s == null) null; if (x < 0) x = 0; int n = s.length(); if (y < x) y = x; if (y > n) y = n; if (x >= y) ret ""; // TODO: Is this actually faster than reversed(substring(...))? char[] chars = new[y-x]; int j = y-x; for (int i = x; i < y; i++) chars[--j] = s.charAt(i); ret String.valueOf(chars); }