[英]StringBuilder.append alternative
Hi can someone suggest to me how I can refactor this code from using x.append and use only appened ( removing the x. every time).嗨,有人可以向我建议如何使用 x.append 重构此代码并仅使用附加(每次都删除 x.)。 Thanks谢谢
StringBuilder x = new StringBuilder();
x.append("\n.O/");
x.append(fields.nextToken());
x.append("/");
x.append(fields.nextToken()); // Date
x.append("/");
x.append(fields.nextToken());
x.append("/Y");
It sounds like the specific code you're looking for is just听起来您正在寻找的特定代码只是
StringBuilder x = new StringBuilder();
x.append("\n.O/")
.append(fields.nextToken())
.append("/")
.append(fields.nextToken()) // Date
.append("/")
.append(fields.nextToken())
.append("/Y");
There are several other -- arguably better -- approaches to writing this code, but you specifically asked for chaining the append statements.还有其他几种(可以说更好)编写此代码的方法,但您特别要求链接 append 语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.