Please can someone kindly explain why the output is not [HeLLo,Hello,HeLLo].
import java.util.ArrayList;
import java.util.List;
/* Consider below code:
* What will be the result of compiling and executing
Test class?
* A) [HeLLo, Hello, Hello]
* B) [Hello, Hello, Hello] CORRECT ANSWER
* C) [HeLLo, HeLLo, HeLLo]
* D) [HeLLo, Hello, HeLLo] WRONG ANSWER
*/
public class _27_Question_Manipulating_ArrayList {
public static void main(
String[] args) {
String s = new String("Hello");
List<String> list = new ArrayList<>();
list.add(s); // obj ref 1
list.add(new String("Hello")); // obj ref 2
list.add(s); // obj ref 1
s.replace("l", "L");
System.out.println(list);
}
}
Thanks for any help that you can give.