sS reversedSubstring(S s, int x, int y) { if (s == null) null; if (x < 0) x = 0; int n = s.length(); if (x >= n) ret ""; if (y < x) y = x; y = Math.min(y, n); // 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); }