StringIndexOutOfBoundsException « string « Java Data Type Q&A





1. Why am I getting a StringIndexOutOfBoundsException when I try to replace `\\` with `\`?    stackoverflow.com

I have to replace \\ with \ in Java. The code I am using is

System.out.println( (MyConstants.LOCATION_PATH + File.separator + myObject.getStLocation() ).replaceAll("\\\\", "\\") );
But I don't know why it is throwing ...

2. StringIndexOutOfBoundsException    stackoverflow.com

This program I'm making isn't compiling right, I keep getting the error: Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -9 at java.lang.String.charAt(String.java:687) at pro1.main(pro1.java:161) Here's my code:

import java.io.*;
import java.util.*;
public ...

3. Why am I getting java.lang.StringIndexOutOfBoundsException?    stackoverflow.com

I want to write a program that prints words incrementally until a complete sentence appears. For example : I need to write (input), and output:

I
I need