- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我最近读到在StringWriter
和StringReader
中用于写入和读取StringBuilder
。
当我使用 StringBuilder
对象时,它看起来是一个自给自足的类。
我们有各种读写 StringBuilder
的方法,使用StringBuilder.Append()
、Insert()
、Replace()
、Remove()
等...
StringWriter
和 StringReader
有什么可能的用途,而这不能由 StringBuilder
本身完成?Stream
作为输入的可能原因是什么(因为任何其他编写者和读者都将流作为要操作的构造函数参数)但 StringBuilder
?最佳答案
What is the possible use of StringWriter and StringReader, which cannot be done by StringBuilder itself?
StringReader
和 StringWriter
分别派生自 TextReader
和 TextWriter
。因此,它们可以作为 TextReader
或 TextWriter
实例,而 string
或 StringBuilder
不能,因为它们不派生出这些类型中的任何一种。
What is the practical use of them?
它们允许您调用需要 TextReader
或 TextWriter
的 API,当您拥有/想要的是 string
或 字符串生成器
。
What could be the possible reason they are not taking up Stream as the input (Because any other writer and reader are taking the stream as the Constructor parameter to operate on) but the StringBuilder?
因为它们不适用于流;它们在 string
或 StringBuilder
上工作。它们只是简单的包装器类,为需要不同接口(interface)的 API 调整这些类型。请参阅:adapter pattern .
关于c# - StringBuilder 与 StringWriter/StringReader,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3392794/
公共(public)类TestMyStringBuilderII { public static void main(String[] args) { StringBuilder sb = n
我们都知道字符串是不可变的而StringBuilder是可变的。正确的。那么为什么它的方法会返回一个 StringBuilder 对象。它们不应该都是 void 方法吗? 为什么会这样 public
当我读到 equals() 方法用于比较 java 中的字符串是否相等但是当我运行这段代码时我得到输出 false 。为什么? public class TestStringBuilder { pu
我收到一份模型列表。模型的数量可能很大。这个模型有一堆属性,其中任何一个都可能是null。 我需要根据模型的属性为每个模型构建一个字符串。如果 property == null,那么我会在结果字符串中
我写了一些代码,其中有很多字符串创建。为了尽量避免一遍又一遍地创建昂贵的字符串,我使用了 java StringBuilder 类。 我的代码有点像这样: public String createSt
这个问题在这里已经有了答案: 关闭10年前。 Possible Duplicate: StringBuilder vs String concatenation in toString() in Ja
类 StringBuilder 定义了四个构造函数,它们都不接受 StringBuilder,但以下编译: StringBuilder sb = new StringBuilder(new Strin
我正在努力在我的代码中使用 StringBuilder,而不是 String使代码在所有解析和连接过程中具有时间效率。 但是当我查看它的源代码时,substring() 方法AbstractStrin
我想知道 StringBuilder,我有一个问题希望社区能够解释。 让我们忘掉代码的可读性,哪些是更快,为什么? StringBuilder.Append: StringBuilder sb = n
这个问题在这里已经有了答案: Single exclamation mark in Kotlin (6 个回答) Example of when should we use run, let, app
我已经附加了一些带有一些字符的 strBuild 并将该 strBuild 放入 stringBuildArr 中。然后在strBuild上调用java.lang.StringBuilder.dele
在 C# 中哪个内存效率更高:选项 #1 还是选项 #2? public void TestStringBuilder() { //potentially a collection with
当使用 StringBuilder.ToString() 时,我遇到了 OutOfMemory 异常。因为我的字符串需要很大的空间。这就是为什么我需要一种方法(也许通过流式传输)来让它工作。 这是我的
这个问题已经有答案了: What's the difference between instance method reference types in Java 8? (3 个回答) 已关闭 7 年
这个问题在这里已经有了答案: What's the difference between instance method reference types in Java 8? (3 个答案) 关闭
最近的 question came up关于使用 String.Format()。我的部分回答包括使用 StringBuilder.AppendLine(string.Format(...)) 的建议
在 SO 上看到一个关于连接字符串的问题后,我做了一些测试,了解到在 foreach 中连接字符串比使用 for 循环和使用数组中的索引慢。由于对数组进行绑定(bind)检查,for 循环不应该变慢吗
我的问题是如果我有时在同一个字符串上使用多线程 字符串不会被替换。(我在记事本上写了这个,所以语法可能是 错误) 使用 System.Thread ...当然还有其他 class .... {
如果我创建一个不可变类。所有字段都必须是最终的。如果我像这样使用 stringbuilder final StringBuilder s = new StringBuilder("你好"); ,那么
是否可以配置 Java StringBuilder类在每次调用之间追加一个新行以追加? 最佳答案 我不认为 StringBuilder内置了该功能。既然你不能只是扩展它,你可以尝试使用装饰器模式...
我是一名优秀的程序员,十分优秀!