Best practices/performance: mixing StringBuilder.append with String.concat

前端 未结 9 536
孤独总比滥情好
孤独总比滥情好 2020-12-07 08:23

I\'m trying to understand what the best practice is and why for concatenating string literals and variables for different cases. For instance, if I have code like this

9条回答
  •  感情败类
    2020-12-07 08:58

    Use + operator is best practice, it is also simple and readable.

    The Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings. String concatenation is implemented through the StringBuilder(or StringBuffer) class and its append method.

    Offical document: https://docs.oracle.com/javase/8/docs/api/java/lang/String.html

提交回复
热议问题