第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

請(qǐng)教在Java中該如何實(shí)現(xiàn)MyString1類(lèi)中的這個(gè)函數(shù)?如下所示!

請(qǐng)教在Java中該如何實(shí)現(xiàn)MyString1類(lèi)中的這個(gè)函數(shù)?如下所示!

public MyString1 substring(int begin,int end) //提取子串{}
查看完整描述

2 回答

?
慕沐林林

TA貢獻(xiàn)2016條經(jīng)驗(yàn) 獲得超9個(gè)贊

不知道你說(shuō)的實(shí)現(xiàn)是怎么個(gè)實(shí)現(xiàn)?如果只是調(diào)用的話(huà) str.subString(begin,end)就可以了,如果是java的底層實(shí)現(xiàn)的話(huà),下面是來(lái)自java.lang.String的代碼:


public String substring(int beginIndex, int endIndex) {    if (beginIndex < 0) {        throw new StringIndexOutOfBoundsException(beginIndex);    }    if (endIndex > count) {        throw new StringIndexOutOfBoundsException(endIndex);    }    if (beginIndex > endIndex) {        throw new StringIndexOutOfBoundsException(endIndex - beginIndex);    }    return ((beginIndex == 0) && (endIndex == count)) ? this :        new String(offset + beginIndex, endIndex - beginIndex, value);    }

然后調(diào)用String的一個(gè)私有構(gòu)造器:


// Package private constructor which shares value array for speed.    String(int offset, int count, char value[]) {    this.value = value;    this.offset = offset;    this.count = count;    }



查看完整回答
反對(duì) 回復(fù) 2021-07-04
?
莫回?zé)o

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊

給你個(gè)例子,你參考下


public class $ {    public static void main(String[] args) {         String str = "abcdefg";        System.out.println(substring(str, 01));    }     private static String substring(String str, int begin, int end) {         char[] ch = str.toCharArray();        StringBuffer buf = new StringBuffer();        for (int i = begin; i < end; i++) {            buf.append(ch[i]);        }        return buf.toString();    }}



查看完整回答
反對(duì) 回復(fù) 2021-07-04
  • 2 回答
  • 0 關(guān)注
  • 326 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)