Which of these statements concerning the charAt () method of the String class are true?
Select 2 options
charAt()
method can take a char value as an argument. charAt()
method returns a Character object. Correct Options are : A E
A. is correct. Yes, it can because it takes an int and char will be implicitly promoted to int.
B. is wrong since charAt()
returns char.
C. is wrong since it will assign 4 as indexing starts from 0.
D. is wrong since it will throw IndexOutOfBoundsException as str.length () is 5 and there is no str.charAt (5);
Since indexing starts with 0, the maximum value that you can pass to charAt is length-1.
charAt()
throws IndexOutOfBoundsException if you pass an invalid value.