Very common exception which every java developer might have gone through.
Reason- When try to access the index of the string’s character which is not available.
String sample = “atul”;
//Here you will get the String out of range exception. You are trying to get the index of ‘,’ which is not the character in the string.
sample = sample.substring(0,sample.lastIndexOf(“,”));
Solution: Character must be present in the string before trying to access it.