What is the difference between append and write methods of java.io.writer?

前端 未结 6 797
情话喂你
情话喂你 2020-12-15 03:29

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

An invocation of t

6条回答
  •  Happy的楠姐
    2020-12-15 04:02

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

    • write will only take a String which must not be null and returns void
    • append will take any CharSequence which can be null and return the Writer so it can be chained.

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

    These methods are overloaded so that there is a

    • 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().

提交回复
热议问题