About Question enthuware.ocpjp.i.v11.2.852 :
Posted: Wed Sep 09, 2020 3:27 pm
What will the following code print? System.out.println("12345".charAt(6));
Answer:
It will throw an IndexOutOfBoundsException
but IntelliJ IDEA give output:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 6
at java.lang.String.charAt(String.java:658)
at home.Test.main(Test.java:17)
What is right ?
Thank you for helping
Answer:
It will throw an IndexOutOfBoundsException
but IntelliJ IDEA give output:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 6
at java.lang.String.charAt(String.java:658)
at home.Test.main(Test.java:17)
What is right ?
Thank you for helping