String splicing ""+1, String.valueOf(), str+"str" string splicing difference

analysis:

  • ""+1
    is constant addition, the highest execution efficiency

  • String s= str+"str"
    Since string is finally modified, str+"str" ​​is essentially carried out

     1.创建"str"新对象创建,
    
     2.str+"str"新对象的创建
     3.赋值给s
    

    Object-oriented programming, the most resource consuming is the creation and destruction of objects, so its stitching efficiency is the lowest

  • String.valueOf()

Will directly call the type conversion method, the efficiency is in the middle

Guess you like

Origin blog.csdn.net/weixin_43158695/article/details/113396565