So, I am trying to figure out why String.substring(int startIndex) allows a start index that is out of bounds and does not throw OOB exception?
Here is the code I was testing this with :
public class testSub {
public static void main(String[] args) {
String testString = "D";
String newSub= testString.substring(1); //print everything FROM this index Up, right? Should that not be out of bounds? Yet I just get a blank.
System.out.println(newSub); //this works fine and prints a blank
System.out.println(testString.charAt(1)); // <Yet this throws OOB?
System.out.println(testString.lastIndexOf("")); // Gives me (1) but I just tried getting it? Should this not mean String length is 2?
}
}
I understand that substrings are substring(inclusive, exclusive), but 1 is clearly out of bounds, so WHY is it giving a blank space instead of throwing OOB, or how is it doing it? Is "" some special exception?