Collections:-
Streams:-
to be edited
ArrayList:-
LinkedList:-
List:-
Set:-
String s1 = "obify" String s2 = "obify"; System.out.println(s1 == s2); Answer: The above code snippet prints output as true because we have created both String objects using double quotes (Sting literals), then they will be part of the string pool and it will print true.
String s1 = new String("obify"); String s2 = new String("obify"); System.out.println(s1 == s2); Answer: The above code snippet prints output as false because we are using a new operator to create String, so it will be created in the heap memory and both s1, s2 will have different references.
String s1 = new String("obify"); String s2 = "obify"; Answer: Here, two string objects will be created. An object created using a new operator(s1) will be stored in the heap memory. The object created using a string literal(s2) is stored in the string constant pool.
String s1 = "obify"; String s2 = "obify"; Answer: Only one object will be created and this object will be stored in the string constant pool.