java 中StringBuffer类有getChars方法吗 为什么我的书上没有介绍呀?

来源:百度知道 编辑:UC知道 时间:2024/05/17 06:17:04
我的书上只在String类介绍拉在StringBuffer类中并没有介绍,可是他在StringBuffer中切用到拉getChars方法,为什么?
那么着两个类中的getChars方发有什么区别吗?

有的
以下来自JDK的Docs:

public void getChars(int srcBegin,int srcEnd,char[] dst,int dstBegin)
-------------------------
Characters are copied from this string buffer into the destination character array dst. The first character to be copied is at index srcBegin; the last character to be copied is at index srcEnd-1. The total number of characters to be copied is srcEnd-srcBegin. The characters are copied into the subarray of dst starting at index dstBegin and ending at index:

dstbegin + (srcEnd-srcBegin) - 1
-------------------------------
[Parameters]:
srcBegin - start copying at this offset in the string buffer.
srcEnd - stop copying at this offset in the string buffer.
dst - the array to copy the data into.
dstBegin - offset into dst.
-----------------------------
[Throws]:
NullPointerException - if dst is null.
IndexOutOfBoundsException - if any of the following is true:
srcBegin is negativ