昨天发现一个IDE提示:

String concatenation as argument to 'StringBuffer.append()' call less... (Ctrl+F1)

Reports String concatenation used as the argument to StringBuffer.append(),StringBuilder.append() orAppendable.append(). Such calls may profitably be turned into chained append calls on the existingStringBuffer/Builder/Appendable,
saving the cost of an extraStringBuffer/Builder allocation.

This inspection ignores compile time evaluated String concatenations, which when converted to chained append calls would only worsen performance.

这段英文看的意思不是很明白怎么回事,

        str.append("Date: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "\n");
str.append("Version: " + info.versionName + "(" + info.versionCode + ")\n");

代码大概是这样的后面还有很多 append 。

后来我才反应过来,是里面的参数的问题。

本来  append 方法就是拼接字符串用的,而参数里面又用了 + 加号来拼接字符串,于是就提示你应该用 append 将这些字符串作为参数来使用~~~

不过如果真的全用 append 来写的话,那这段代码阅读起来可就要命了,所以还是忽略这个提示了

StringBuffer使用append提示String concatenation as argument to 'StringBuffer.append()' call的更多相关文章

  1. StringBuilder的append、StringBuffer的append和String str = "a"+"b"的区别?

    大家都知道String+String会开销额外的系统资源,粗略的原因是String是不可变类,每一步操作都会返回新的String变量,占用空间及时间. 其实我的理解不是这样的,我们来看看String+ ...

  2. 从源代码的角度聊聊java中StringBuffer、StringBuilder、String中的字符串拼接

    长久以来,我们被教导字符串的连接最好用StringBuffer.StringBuilder,但是我们却不知道这两者之间的区别.跟字符串相关的一些方法中总是有CharSequence.StringBuf ...

  3. 从为什么String=String谈到StringBuilder和StringBuffer

    前言 有这么一段代码: public class TestMain { public static void main(String[] args) { String str0 = "123 ...

  4. Effective Java 51 Beware the performance of string concatenation

    Using the string concatenation operator repeatedly to concatenate n strings requires time quadratic ...

  5. CodeForces 632C The Smallest String Concatenation//用string和sort就好了&&string的基础用法

    Description You're given a list of n strings a1, a2, ..., an. You'd like to concatenate them togethe ...

  6. JAVA String、StringBuilder、和StringBuffer的区别,及如何使用

    目录 String类 一.String类的理解和创建对象 二.String类创建的方式 两种创建String对象的区别 测试题 三.String常用方法 四.StringBuffer类 1.Strin ...

  7. Leetcode541/151之String与char数组与StringBuffer

    String与char数组与StringBuffer 通常情况下遇到删除字符或者反转字符串时需要将String转为char数组或者StringBuffer String与char数组 char [] ...

  8. Java基础(32):String与StringBuilder、StringBuffer的区别(String类)

    在Java中,除了可以使用 String 类来存储字符串,还可以使用 StringBuilder 类或 StringBuffer 类存储字符串,那么它们之间有什么区别呢? String 类具有是不可变 ...

  9. ORA-01489: result of string concatenation is too long

    ORA-01489: result of string concatenation is too long Cause: String concatenation result is more tha ...

随机推荐

  1. 增删查改-MySQL

    查询: 在MySQL中,select的基本语法形式: select 属性列表 from 表名和视图 [where 条件表达式] [group by 属性名 [having 条件表达式]] [order ...

  2. vim简单的实用总结

    vim简单的实用总结 介绍vim常用的四种模式:一般模式,编辑模式,指令列命令模式与可视模式.一,一般模式   用vim filename打开文件后直接进入的就是一般模式,在这个模式下可以用hjkl移 ...

  3. windbg Symbol file path

    SOS是一个调试器扩展,用于调试.NET应用程序.它提供了一组非常丰富的命令,这些命令使开发人员可以对CLR进行深入分析,并且有助于找出应用程序中各种复杂错误的原因.   由于SOS能够提供CLR内部 ...

  4. MVC几种传值方式

    一,Model public class Course { public int Id { get; set; } public string Name { get; set; } } public ...

  5. 马丁·福勒-page对象

    马丁·福勒-page对象 译者注:这篇文章翻译自马丁·福勒(Martin Flower,对,没错,就是软件教父)官网的一篇文章,原文出处在文底.如果你正在做WEB自动化测试,那么我强烈推荐你看这篇文章 ...

  6. 无穷字符串问题--CSDN上的面试题(原创)

    网上看到一道奇怪的题,分享一下:http://hero.csdn.net/Question/Details?ID=307&ExamID=302 发布公司:CSDN 有 效 期:2014-02- ...

  7. 运用Unity实现AOP拦截器

    运用Unity实现AOP拦截器[结合异常记录实例] 本篇文章将通过Unity实现Aop异常记录功能:有关Unity依赖注入可以看前两篇文章: 1:运用Unity实现依赖注入[结合简单三层实例] 2:运 ...

  8. jQuery Validation让验证变得如此容易(三)

    以下代码进行对jQuery Validation的简单演示包括必填项.字符长度,格式验证 一.引入文件 <script src="js/jquery-1.8.0.min.js" ...

  9. 鸟哥的LINUX私房菜基础篇第三版 阅读笔记 三 Linux磁盘与文件系统管理

    一.认识EXT2文件系统:     a.硬盘的组成:转动小马达+存储的磁盘+读写的机械臂     b.磁盘的一些概念              扇区为最小的物理储存单位,每个扇区为512B       ...

  10. HDU 4062 Partition

    Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...