string memory allocation

后端 未结 4 1634
[愿得一人]
[愿得一人] 2021-01-22 14:49

which one is better

System.out.println(\"hello world\");

or

String s=\"hello world\";
System.out.println(s);
4条回答
  •  生来不讨喜
    2021-01-22 15:47

    No difference.

    But, if you were to compare

    String s=new String("hello world");
    System.out.println(s);
    

    with

    System.out.println("hello world");
    

    Then there would be a potential difference, as the latter case would be a candidate for string internalisation, wheras the former would not.

提交回复
热议问题