StringBuffer使用append提示String concatenation as argument to 'StringBuffer.append()' call
昨天发现一个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的更多相关文章
- StringBuilder的append、StringBuffer的append和String str = "a"+"b"的区别?
大家都知道String+String会开销额外的系统资源,粗略的原因是String是不可变类,每一步操作都会返回新的String变量,占用空间及时间. 其实我的理解不是这样的,我们来看看String+ ...
- 从源代码的角度聊聊java中StringBuffer、StringBuilder、String中的字符串拼接
长久以来,我们被教导字符串的连接最好用StringBuffer.StringBuilder,但是我们却不知道这两者之间的区别.跟字符串相关的一些方法中总是有CharSequence.StringBuf ...
- 从为什么String=String谈到StringBuilder和StringBuffer
前言 有这么一段代码: public class TestMain { public static void main(String[] args) { String str0 = "123 ...
- Effective Java 51 Beware the performance of string concatenation
Using the string concatenation operator repeatedly to concatenate n strings requires time quadratic ...
- 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 ...
- JAVA String、StringBuilder、和StringBuffer的区别,及如何使用
目录 String类 一.String类的理解和创建对象 二.String类创建的方式 两种创建String对象的区别 测试题 三.String常用方法 四.StringBuffer类 1.Strin ...
- Leetcode541/151之String与char数组与StringBuffer
String与char数组与StringBuffer 通常情况下遇到删除字符或者反转字符串时需要将String转为char数组或者StringBuffer String与char数组 char [] ...
- Java基础(32):String与StringBuilder、StringBuffer的区别(String类)
在Java中,除了可以使用 String 类来存储字符串,还可以使用 StringBuilder 类或 StringBuffer 类存储字符串,那么它们之间有什么区别呢? String 类具有是不可变 ...
- 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到n的正整数中1的个数
问题: 给定一个十进制正整数N,写下从1开始,到N的所有整数,然后数一下其中出现的所有“1”的个数. 例如:N= 2,写下1,2.这样只出现了1个“1”. N= 12,我们会写下1, 2, 3, 4, ...
- TD中{text-overflow:ellipsis;} 用法
Styles: table{ table-layout:fixed; } table td{ text-overflow:ellipsis;overflow:hidden;white-space: n ...
- IOS学习之路二十三(EGOImageLoading异步加载图片开源框架使用)
EGOImageLoading 是一个用的比较多的异步加载图片的第三方类库,简化开发过程,我们直接传入图片的url,这个类库就会自动帮我们异步加载和缓存工作:当从网上获取图片时,如果网速慢图片短时间内 ...
- 整合MVVM框架(Prism)
整合MVVM框架(Prism) 我们基础的框架已经搭建起来了,现在整合MVVM框架Prism,在ViewModel做一些逻辑处理,真正把界面设计分离出来. 这样方便我们系统开发分工合作,同时提高系统可 ...
- C#代码和javascript函数相互调用
C#代码与javaScript函数的相互调用 问:1.如何在JavaScript访问C#函数?2.如何在JavaScript访问C#变量?3.如何在C#中访问JavaScript的已有变量?4.如何在 ...
- WCF 学习笔记之异常处理
WCF 学习笔记之异常处理 1:WCF异常在配置文件 <configuration> <system.serviceModel> <behaviors> <s ...
- 使用ServletContextListener和HttpSessionListener两种监听器实现记录当前网站在线人数
web.xml中配置: <listener> <listener-class>com.mcm.listener.ServletContextListenerImpl< ...
- [C++]neuroscan的延时预估
一直用自己写的程序在线处理脑电信号,知道其中有一个时间延时,但具体延时是多少没有是个准确的估计,今天抽时间做了一下,发现大概延时在100ms左右. 以后尝试使用并口操作.应该可以完全避免这个问题. 实 ...
- apache+php+mysql的分布安装
一.Apache+php+mysql的版本: Apache:2.2.22 Mysql:5.5.24 Php:5.3.13 二.apache+php+mysql的分布安装 注意:卸载软件之前要先停止服务 ...
- Python中BeautifulSoup中对HTML标签的提取
一开始使用了beautifulSoup的get_text()进行字符串的提取,后来一直提取失败,并提示错误为TypeError: 'NoneType' object is not callable 返 ...