why java "c".substring(1); returns a blank string "" though beginIndex 1 is not present in provided string [duplicate]

This question already has an answer here:

Why is “out of range” not thrown for 'substring(startIndex, endIndex)'

6 answers

substring(int) method magically doesn't throw StringIndexOutOfBoundsException

6 answers

Why does the java substring method work like this?

3 answers

Why java substring doesn't crash?

3 answers

Substring strange Bounds?

6 answers

I came across a problem that if we calls a substring() method with beginIndex argument as 1 i.e substring(1); on a string contained only single character returns a blank string "", though index 1 is not present in a provided string.

public class StringPermutations {

public static void main(String[] args) {

String s="C".substring(1); //returns...

Read More »

By: StackOverFlow - Wednesday, 9 January

Related Posts