Use safe replacemethod (eliminates IndexOutOfBoundsException)