How many String object..?

前端 未结 6 1331
礼貌的吻别
礼貌的吻别 2021-01-18 13:36

Me and my friend was discussing on Strings and we stuck on this:

String str = \"ObjectOne\"+\"ObjectTwo\";

He says total three Object will

6条回答
  •  野的像风
    2021-01-18 14:31

    String str = "ObjectOne"+"ObjectTwo";
    

    3 objects will be created as

    1- "ObjectOne"

    2- "ObjectTwo"

    3- "ObjectOneObjectTwo"

    use

    StringBuffer tmp = new StringBuffer("ObjectOne");
    tmp.append("ObjectTwo");
    str = tmp.toString();
    

提交回复
热议问题