简体   繁体   English

Apache commons-lang StrBuilder与Java land StringBuilder有什么区别?

[英]What is the difference between Apache commons-lang StrBuilder vs Java land StringBuilder?

How StrBuilder in Apache commons lang is different from Java lang api. Apache Commons lang中的StrBuilder与Java lang API有何不同。

In Apache commons-lang3 i see StrBuilder is deprecated. 在Apache commons-lang3中,我看到StrBuilder已过时。

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

or can i use Java Lang StringBuilder instead? 或者我可以改用Java Lang StringBuilder吗?

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

From my understanding, it closely resembles the Java StringBuilder's design but adds additional functionality to it. 根据我的理解,它与Java StringBuilder的设计非常相似,但是为其添加了附加功能。 From the Apache Common Lang's JavaDoc , the main differences are: 与Apache Common Lang的JavaDoc相比 ,主要区别在于:

  • Not synchronized 未同步
  • Not final 不是最终的
  • Subclasses have direct access to character array 子类可以直接访问字符数组

    Additional methods 其他方法

  • appendWithSeparators - adds an array of values, with a separator appendWithSeparators-使用分隔符添加值数组

  • appendPadding - adds a length padding characters appendPadding-添加长度填充字符
  • appendFixedLength - adds a fixed width field to the builder appendFixedLength-向构建器添加固定宽度的字段
  • toCharArray/getChars - simpler ways to get a range of the character array toCharArray / getChars-获取字符数组范围的更简单方法
  • delete - delete char or string 删除-删除字符或字符串
  • replace - search and replace for a char or string replace-搜索并替换字符或字符串
  • leftString/rightString/midString - substring without exceptions leftString / rightString / midString-子字符串,无异常
  • contains - whether the builder contains a char or string 包含-构建器是否包含字符或字符串
  • size/clear/isEmpty - collections style API methods size / clear / isEmpty-集合样式API方法

    Views 查看

  • asTokenizer - uses the internal buffer as the source of a StrTokenizer asTokenizer-使用内部缓冲区作为StrTokenizer的源

  • asReader - uses the internal buffer as the source of a Reader asReader-使用内部缓冲区作为Reader的源
  • asWriter - allows a Writer to write directly to the internal buffer asWriter-允许Writer直接写入内部缓冲区

To answer whether or not you can use it, StrBuilder was depracated in newer versions in favor of org.apache.commons.text.TextStringBuilder. 为了回答您是否可以使用它,StrBuilder在较新的版本中被弃用,取而代之的是org.apache.commons.text.TextStringBuilder。 This was done to avoid confusion with StringBuilder. 这样做是为了避免与StringBuilder混淆。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM