String類的常用操作方法列舉

2021-09-12 07:40:41 字數 1788 閱讀 6114

public static void main(string args) ;

//1. 將字元陣列中的所有內容變為字串

string str = new string(data);

system.out.println(str);

//2.將部分字元陣列中的內容變為字串

string str2 = new string(data,2,3);

system.out.println(str2);

//3.取得指定索引位置的字元

string str3 = "hello";

system.out.println(str3.charat(4));

//4.將字串變為字元陣列返回

string str4 = "world";

char data2 = str4.tochararray();

for(int i = 0;i}

}執行結果:

abcdefg

cdeo

w、o、r、l、d、

public static void main(string args) 

//2.將位元組陣列變為字串

system.out.println(new string(data));

//3.將部分位元組陣列中的內容轉換成字串

system.out.println(new string(data,3,4));

}}執行結果:

104、101、108、108、111、119、111、114、108、100、

helloworld

lowo

public static void main(string args) 

}執行結果:

false

true

true

7

public static void main(string args) 

}執行結果:

true4-1

244true

true

true

public static void main(string args) 

}執行結果:

he__o wor_d

he_lo world

public static void main(string args) 

//2.將字串部分拆分,該陣列長度就是limit極限。

string result2 = str1.split(" ",3);

for(string s:result2)

}}執行結果:

hello

world

hello

china!

hello

world

hello china!

public static void main(string args) 

}執行結果:

world

ello

public static void main(string args) 

}執行結果:

hello world

hello world

hello world

hello world

hello world hello china!

13false

String類的常用操作方法

字元與字串 構造方法 將全部的字元陣列變為字串 public string char data 構造方法 將部分字元陣列變為字串 public string char data int offset int count 普通方法 將字串變為字元陣列 public char tochararray 普...

String的常用操作方法

在string類中提供了以下的方法操作字元與字串間的轉換關係 根據字串中提供的索引找到指定位置的字元 public charcharat int index 將字串變為字元陣列 public chartochararray 將字元陣列變為字串 將全部的字元陣列變為string型別 publicstr...

String類 常用 操作 方法 合集 慢慢完善

string用的挺多,但是針對它的操作方法時間長了不用還真想不起來,總結一下子的話,這裡先總結下常用的 返回值型別 基本操作方法 機能boolean equals string str 和其他字串相等時返回true char charat int pos 獲取字串中的第i個字元 intindexof...