Appendable

public interface Appendable能夠被追加 char 序列和值的對象。如果某個類的實例打算接收來自 Formatter 的格式化輸出,那么該類必須實現 Appendable 接口。

基本介紹

  • 中文名:Appendable
  • 使用類型:java.lang
  • 已知實現類:StringBuffer, StringBuilder
  • 軟體原理:能夠被追加 char 序列和值的對象
使用類型,軟體原理,方法摘要,

使用類型

java.lang
接口 Appendable
所有已知實現類:
StringBuffer, StringBuilder
--------------------------------------------------------------------------------

軟體原理

要追加的字元應該是有效的 Unicode 字元,正如 Unicode Character Representation 中描述的那樣。注意,增補字元可能由多個 16 位 char 值組成。
Appendable 對於多執行緒訪問而言沒必要是安全的。執行緒安全由擴展和實現此接口的類負責。
由於此接口可能由具有不同的錯誤處理風格的現有類實現,所以無法保證錯誤不會傳播給調用者。
從以下版本開始:
1.5
--------------------------------------------------------------------------------

方法摘要

Appendable append(char c)
向此 Appendable 追加指定字元。
Appendable append(CharSequence csq)
向此 Appendable 追加指定的字元序列。
Appendable append(CharSequence csq, int start, int end)
向此 Appendable 追加指定字元序列的子序列。
方法詳細信息
append
Appendable append(CharSequence csq)
throws java.io.IOException向此 Appendable 追加指定的字元序列。
有時可能沒有追加整個序列,這取決於使用哪個類來實現字元序列 csq。例如,如果 csq 是 CharBuffer 的一個實例,則通過緩衝區的位置和限制來定義要追加的子序列。
參數:
csq - 要追加的字元串序列。如果 csq 為 null,則向該 Appendable 追加四個字元 "null"。
返回:
此 Appendable 的引用
拋出:
java.io.IOException - 如果發生 I/O 錯誤
--------------------------------------------------------------------------------
append
Appendable append(CharSequence csq,
int start,
int end)
throws java.io.IOException向此 Appendable 追加指定字元序列的子序列。
當 csq 不為 null 時,用 out.append(csq, start, end) 的形式調用此方法與用以下形式調用此方法的行為完全相同:
out.append(csq.subSequence(start, end))
參數:
csq - 子序列將被追加的字元序列。如果 csq 為 null,則追加四個字元 "null",就好像 csq 包含這些字元一樣。
start - 子序列中第一個字元的索引
end - 緊隨子序列中最後一個字元的字元的索引
返回:
此 Appendable 的引用
拋出:
IndexOutOfBoundsException - 如果 start 或 end 為負,以及 start 大於 end 或者 end 大於 csq.length()
java.io.IOException - 如果發生 I/O 錯誤
--------------------------------------------------------------------------------
append
Appendable append(char c)
throws java.io.IOException向此 Appendable 追加指定字元。
參數:
c - 要追加的字元
返回:
此 Appendable 的引用
拋出:
java.io.IOException - 如果發生 I/O 錯誤

熱門詞條

聯絡我們