本文介绍了java.io.writer的append和write方法有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

界面有两个方法叫做追加和写。这两者有什么区别?它甚至说

The java.io.Writer interface has two methods called append and write. What are the differences between these two? It even says that

那么有两个方法名称变体的原因是什么?

so what is the reason for having two method name variants?

推荐答案

append()和write()之间存在细微差别。所有这些都可以通过阅读Javadocs来解决。暗示。 ;)

There are minor differences between append() and write(). All of which you can work out by reading the Javadocs. Hint. ;)


  • write只接受一个不能为null的字符串并返回 void

  • append将接受任何CharSequence,它可以为null并返回Writer,以便它可以被链接。

write是在CharSequence可用之前创建的旧样式格式。

write is an older style format created before CharSequence was available.

这些方法已超载,因此存在

These methods are overloaded so that there is a


  • write(int)其中 int 被强制转换为char 。 append(char)必须是char类型。

  • write(char [] chars)接受一个char数组,没有等效的append()。

  • write(int) where the int is cast to a char. append(char) must be a char type.
  • write(char[] chars) takes an array of char, there is no equivalent append().

这篇关于java.io.writer的append和write方法有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 08:10
查看更多