昨天发现一个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. RPC(Remote Procedure Call Protocol)

    远程过程调用协议: 1.调用客户端句柄:执行传送参数 2.调用本地系统内核发送网络消息 3.消息传送到远程主机 4.服务器句柄得到消息并取得参数 5.执行远程过程 6.执行的过程将结果返回服务器句柄 ...

  2. HTML文档类型

    在HMTL5中页面的最顶端代码就是: <!DOCTYPE html> 为何要如此定义.书写呢? 首先引入一个概念:文档类型,英译为:Document type,缩写成:doctype. 文 ...

  3. 实现Avl平衡树

    实现Avl平衡树   一.介绍 AVL树是一种自平衡的二叉搜索树,它由Adelson-Velskii和 Landis于1962年发表在论文<An algorithm for the organi ...

  4. 如何使用Add-on SDK开发一个自己的火狐扩展

    黄聪:如何使用Add-on SDK开发一个自己的火狐扩展 火狐开放了扩展的开发权限给程序员们,相信很多人都会希望自己做一些扩展来方便一些使用. 我最近做一些项目也需要开发一个火狐扩展,方便收集自己需要 ...

  5. STL迭代器与部分算法学习笔记

    迭代器是类似指针的对象,分为5种,输入,输出,前向,双向和随机访问 输入迭代器(InputIterator) 输入迭代器并不是指某种类型,而是指一系列类型 举例 template<class I ...

  6. Xcode4.6 开发 metaio 增强现实 项目(二)--增强现实的实现

    经过昨天的一些步骤,我们已经将我们的IOS应用的基本界面搭建好,下面我们将开始新的征程:增强现实技术的实现: 进入webView后,我们要选用我们这次需要用的nib文件,它是一个家居摆放应用的界面文件 ...

  7. spring mvc下shiro的session,request等问题

    最近的一个项目使用的是spring mvc,权限框架使用的是shiro. 不过有一个问题一直困扰着我,现在的session到底是谁的session,是servlet的还是shiro的. 于是我把spr ...

  8. asp.net MVC 模拟实现与源码分析

    前言 本文流程#1: 从一个空项目->模拟实现一个从/Home/Test形式的URL敲入->后台逻辑处理->传入后台model参数->调用razor引擎->前台展示 涉及 ...

  9. Java开发工具箱-JDK的安装与配置

    一.JDK.JRE 术语名 缩写 解释 Java Development Kit JDK Java程序员用的工具包 Java Runtime Enviroment JRE Java程序的运行环境 二. ...

  10. 菜鸟互啄:WINFORM如何实现无聚焦框的Button按钮

    当我们将一个button按钮设置如下属性时,总有一个聚焦框来困扰着我们 button1.FlatStyle = FlatStyle.Flat; 我们想要的效果是这样的: 但当使用了Tab切换焦点时 发 ...