Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Whats the use of the String constructor?

constructor String
0
10 Posted

Whats the use of the String constructor?

0

The explicit String constructor has the same result as using double quotes to implicitly create a string reference, in both cases the given string is assigned to the reference variable. However, passing a double quoted string argument to the String constructor actually makes two strings; the argument string is implicitly created inline and then its contents are copied to the new String instance. For this reason this constructor is largely redundant and not recommended for general purposes. The String constructor with String argument is rarely used except to create an independent copy of an existing string variable.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.