Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String empty constructor in java [closed]

Tags:

java

string

I was looking into the String API and suddenly I came across one String empty Constructor i.e. we can construct an empty String object using String s = new String()

I wonder is there any use of it?

like image 298
Anand Avatar asked Sep 14 '12 18:09

Anand


1 Answers

Small example... String can be garbage collected

System.out.println(1 + new String() + 2);

instead of

System.out.println(1 + "" + 2);
like image 199
Satya Shekhar Barik Avatar answered Sep 18 '22 06:09

Satya Shekhar Barik