Which of the following statements is preferred to create a string "Welcome to Java"?

a. String s = "Welcome to Java";
b. String s = new String("Welcome to Java");
c. String s; s = "Welcome to Java";
d. String s; s = new String("Welcome to Java");


a (a) is better than (b) because the string created in (a) is interned. Since strings are immutable and are ubiquitous in programming, to improve efficiency and save memory, the JVM uses a unique instance for string literals with the same character sequence. Such an instance is called interned. The JVM (a) is simpler than (c).

Computer Science & Information Technology

You might also like to view...

It is recommended to preview results before running a delete query

Indicate whether the statement is true or false

Computer Science & Information Technology

Setting the list-style-type to ____ causes the bullets in front of each list item to not be displayed.

A. zero B. none C. 0 D. hide

Computer Science & Information Technology

What is the formula to calculate the number of subnets?

What will be an ideal response?

Computer Science & Information Technology

One form of spoofing involves forging the return address on an e-mail so that the e-mail message appears to come from someone other than the sender.

a. true b. false

Computer Science & Information Technology