stringbuilder - Apache Common 的 StrBuilder 和 Java 的 StringBuilder 有什么区别?

标签 stringbuilder apache-commons-lang apache-commons-lang3

Apache Commons 的 StrBuilder 与 Java 的 StringBuilder 有何不同?

在 Apache Commons 中,我看到 StrBuilder 已被弃用。

import org.apache.commons.lang3.text.StrBuilder;
StrBuilder sb = new StrBuilder();

我可以使用 Java 的 StringBuilder 来代替吗?

java.lang.StringBuilder
StringBuilder sb1=new StringBuilder();

最佳答案

根据我的理解,它与 Java StringBuilder 的设计非常相似,但添加了额外的功能。 From the Apache Common Lang's JavaDoc ,主要区别是:

  • Not synchronized
  • Not final
  • Subclasses have direct access to character array

    Additional methods

  • appendWithSeparators - adds an array of values, with a separator

  • appendPadding - adds a length padding characters
  • appendFixedLength - adds a fixed width field to the builder
  • toCharArray/getChars - simpler ways to get a range of the character array
  • delete - delete char or string
  • replace - search and replace for a char or string
  • leftString/rightString/midString - substring without exceptions
  • contains - whether the builder contains a char or string
  • size/clear/isEmpty - collections style API methods

    Views

  • asTokenizer - uses the internal buffer as the source of a StrTokenizer

  • asReader - uses the internal buffer as the source of a Reader
  • asWriter - allows a Writer to write directly to the internal buffer

为了回答是否可以使用它,StrBuilder 在新版本中已被弃用,取而代之的是 org.apache.commons.text.TextStringBuilder。这样做是为了避免与 StringBuilder 混淆。

关于stringbuilder - Apache Common 的 StrBuilder 和 Java 的 StringBuilder 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54688811/

相关文章:

java - 使用 stringutils commons.lang version3 转义 XML 适用于 writer

java - 为什么通过 List<String> 进行迭代比拆分字符串和通过 StringBuilder 进行迭代慢?

android - 从返回值设置 TextView

c# - Windows 窗体 - 列表对话框字符串生成器追加新行

java - 为什么apache commons lang是 "lang",lang代表语言吗?

java - 编码 JavaScript

Java 9 JRE 导致 java.lang.NoClassDefFoundError : org/apache/commons/lang3/StringUtils on jar execution

java - Intellij 无法解析符号 'lang3' apache

java - 如何检查给定的字符串转换为long是否是EpochMills?

android - 连接字符串以将多个图像发送到服务器android