java string 异或_Java源码——String
最近在研究java的源代碼,但是由于自己英語水平有限,所以想使用中文注釋的方式把源碼里的方法全部重寫
一遍,下面是樓主整理出來的一小部分。我把整體的項(xiàng)目托管到GitHub上了,歡迎大家前去交流學(xué)習(xí)。
GitHub :?https://github.com/15128928804/yuanMa
/**
* @Author:zhuangfei
* @Description:初始化一個新的 String 對象用來表示一個空的字符序列。
* 注意,這個構(gòu)造方法是沒有使用的必要的,因?yàn)樽址遣豢勺兊?/p>
* @Date:16:48 2017/11/8
*/
public String() {
this.value = "".value;
}
/**
* @Author:zhuangfei
* @Description:初始化一個新的 String對象用來表示相同的字符序列作為參數(shù),
* 換句話說,新創(chuàng)建的字符串是參數(shù)字符串的副本。除非一個‘需要的’顯示拷貝,
* 否則是不必使用此構(gòu)造函數(shù)的,因?yàn)樽址遣豢勺兊?/p>
* @Date:16:53 2017/11/8
*/
public String(String original) {
this.value = original.value;
this.hash = original.hash;
}
/**
* @Author:zhuangfei
* @Description:分配一個新的String用來表示序列字符數(shù)組參數(shù)中包含的字符。
* 在該字符數(shù)組的內(nèi)容被復(fù)制后的修改中,字符數(shù)組不影響新創(chuàng)建的字符串
* @Date:16:58 2017/11/8
*/
public String(char value[]) {
this.value = Arrays.copyOf(value, value.length);
}
/**
* @Author:zhuangfei
* @Description:分配一個新的String對象用來包含來自子數(shù)組的字符
* 字符數(shù)組參數(shù)。offset參數(shù)是子數(shù)組的第一個字符和count位置的索引指定的
* 子數(shù)組的長度的內(nèi)容。
* 子數(shù)組被復(fù)制后對子數(shù)組進(jìn)行修改不影響新創(chuàng)建的字符串
* value:源數(shù)據(jù)
* offset:初始偏移
* count:偏移長度
* PS:如果offset和count所得到的值不在源數(shù)組的下標(biāo)內(nèi),會拋出
* IndexOutOfBoundsException(數(shù)組下標(biāo)越界) 異常
* @Date:17:02 2017/11/8
*/
public String (char value[], int offset, int count) {
if(offset < 0) { // 沒有偏移量
throw new StringIndexOutOfBoundsException(offset); // 拋出索引越界異常
}
if(count <= 0) {
if(count < 0) {
throw new StringIndexOutOfBoundsException(count); // 拋出索引越界異常
}
if(offset <= value.length) { // 初始偏移量<=源數(shù)據(jù)長度時直接返回源數(shù)據(jù)
this.value = "".value;
return;
}
}
// 源碼解釋:偏移量或計數(shù)可能在 -1 附近
if(offset > value.length - count) { // 初始偏移量>源數(shù)據(jù)-初始位置的數(shù)據(jù)后的長度
throw new StringIndexOutOfBoundsException(offset + count); // 拋出索引越界異常
}
this.value = Arrays.copyOfRange(value, offset,offset+count); // 執(zhí)行方法
}
總結(jié)
以上是生活随笔為你收集整理的java string 异或_Java源码——String的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: windows启动恢复错误怎么办 Win
- 下一篇: java美元兑换,(Java实现) 美元