Page 1 of 1

[HD-OCP17/21-Fundamentals Pg 265, Sec. 11.1.6 - manipulating-strings]

Posted: Wed Jan 01, 2025 10:00 am
by raphaelzintec
Furthermore, any method that attempts to access an index that is beyond the range of this array throws IndexOutOfBoundsException.

so basically all String methods throw IndexOutOfBoundsException except substring() which throws StringIndexOutOfBoundsException ?

Re: [HD-OCP17/21-Fundamentals Pg 265, Sec. 11.1.6 - manipulating-strings]

Posted: Wed Jan 01, 2025 11:38 pm
by admin
For most of the methods (that throw IOOBE) of the String class, the JavaDoc say these methods throws IOOBE but the implementation of some of these methods (including substring) throw SIOOBE. Since SIOOBE extends IOOBE, the implementation is technically within the agreed contract.

The JavaDoc for indexOf method says it throws SIOOBE.