Given this example:
package com.company;
public class Main {
public static void main(String[] args) {
String myStr= "Hello World ";
myStr.trim();
int i1= myStr.indexOf(" ");
System.out.println(i1);
}
}
What is the result:
A: An exception is thrown at runtime
B: -1
C: 5
D: 10
I guess it should trim the leading and following spaces from myStr, leaving me with the space at position 5, which was confirmed when I typed in the code.
My question is then why did the example marked the correct answer as "A" instead of "C"? Is it just a typo or is there a special way trim works and I messed up while typing it in? :D