What is the correct way to declare a String in Java?
String str = new String("Hello");
String str = String("Hello");
Why are Strings immutable in Java?
To allow modifications in-place
To ensure thread safety and security
Because Java does not support mutable objects
What will be the output of the following code?
Java
String s1 = "Java";
String s2 = "Java";
System.out.println(s1 == s2);
What will be the output of the following code?
Java
String s1 = new String("Java");
String s2 = new String("Java");
System.out.println(s1 == s2);
Which method is used to concatenate two Strings in Java?
What will be the output of the following code?
Java
String s = "Hello";
s.concat(" World");
System.out.println(s);
How can you make String mutable in Java?
Using StringBuilder or StringBuffer
By modifying the existing String object
What will be the output of the following code?
Java
String s1 = "Hello";
String s2 = s1.concat(" World");
System.out.println(s2);
How does the intern() method affect Strings in Java?
It removes duplicate Strings from memory
It ensures that the String is stored in the String Pool
It modifies the original String
It converts the String into a StringBuffer
What is the advantage of using String over StringBuilder in multi-threaded applications?
String is faster than StringBuilder
String is immutable and therefore thread-safe
String can be modified in place
There are 10 questions to complete.
Take a part in the ongoing discussion
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4