亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請教下,關于在java中replace方法如何使用?

請教下,關于在java中replace方法如何使用?

陪伴而非守候 2021-06-29 11:07:36
希望有具體的例子
查看完整描述

2 回答

?
人到中年有點甜

TA貢獻1895條經驗 獲得超7個贊

public String replace(char oldChar,
char newChar)返回一個新的字符串,它是通過用 newChar 替換此字符串中出現的所有 oldChar 得到的。
如果 oldChar 在此 String 對象表示的字符序列中沒有出現,則返回對此 String 對象的引用。否則,創建一個新的 String 對象,它所表示的字符序列除了所有的 oldChar 都被替換為 newChar 之外,與此 String 對象表示的字符序列相同。

示例:

"mesquite in your cellar".replace('e', 'o')
returns "mosquito in your collar"
"the war of baronets".replace('r', 'y')
returns "the way of bayonets"
"sparring with a purple porpoise".replace('p', 't')
returns "starring with a turtle tortoise"
"JonL".replace('q', 'x') returns "JonL" (no change)

參數:
oldChar - 原字符。
newChar - 新字符。
返回:
一個從此字符串派生的字符串,它將此字符串中的所有 oldChar 替代為 newChar。



查看完整回答
反對 回復 2021-07-05
?
一只名叫tom的貓

TA貢獻1906條經驗 獲得超3個贊

class metho {
public metho() {
}

public static void main(String[] args) {
String firstString = "This is";
String secondString = "Thisis";
if (firstString.equals(secondString)) {
System.out.println("相等");}
else{
System.out.println("不相等");
}
System.out.println(firstString.concat(" hisfather"));
System.out.println(firstString.replace(firstString.lastIndexOf('i'),'z' ));
}
}



查看完整回答
反對 回復 2021-07-05
  • 2 回答
  • 0 關注
  • 249 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號