Which operator is used to concatenate two strings in Java?

Java MCQ: Which operator is used to concatenate two strings in Java?

a) +
b) &
c) &&
d) |

Answer:

a) +

Explanation:

In Java, the + operator is used to concatenate (join together) two strings. When this operator is used between two strings, it creates a new string that is the combination of the two. For example, "Hello" + " World" results in "Hello World".

The + operator is also used for arithmetic addition, but when one or both operands are strings, it performs string concatenation. This operator is widely used in Java for building strings dynamically, especially in scenarios where parts of a string need to be combined based on variable values or expressions.

Reference links:

https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top