String類的常用功能

2021-08-21 22:09:52 字數 3864 閱讀 8711

/*

* string類的常用構造方法

* public string():空構造

* public string(byte bytes):把位元組陣列轉換成字串

* public string(byte bytes,int index,int length):把位元組的一部分轉換成字串

* public string(char value):把字元陣列轉換成字串

* public string(char value,int index,int count):把字元的一部分轉換成字串

* public string(string original):把字串常量值轉成字串

* 字串的方法:

* public int length():返回此字串的長度。

*/public class stringdemo ;

// public string(byte bytes):把位元組陣列轉換成字串

string s = new string(b);

system.out.println(s);

system.out.println("------");

// public string(byte bytes,int index,int length):把位元組的一部分轉換成字串

string s2 = new string(b, 0, 2);

system.out.println(s2);

system.out.println("------");

// 字元陣列

char c = ;

// public string(char value):把字元陣列轉換成字串

string s3 = new string(c);

system.out.println(s3);

system.out.println("------");

// public string(char value,int index,int count):把字元的一部分轉換成字串

string s4 = new string(c, 2, 2);

system.out.println(s4);

}}

/*

* string類的判斷功能:

* boolean equals(object obj);比較兩個字串的內容是否相同,區分大小寫

* boolean equalsignorecase(object obj);比較兩個字串的內容是否相同,忽略大小寫

* boolean contains(string str);判斷大字串中是否包含小字串

* boolean startwith(string str);判斷字串是否以某個指定的字串開頭

* boolean endswith(string str);判斷字串是否以某個指定的字串結尾

* boolean isempty();判斷字串是否為空

* * 注意

* 字串物件為空和字串內容為空不是乙個概念

*

*/public class stringdemo2

}/*結果:

true

false

----------

true

true

----------

true

false

----------

true

false

----------

*/

/*

* string類的獲取功能

* int length();獲取字串的長度

* char charat(int index);獲取指定索引位置的字元

* int indexof(int ch);獲取指定字元在此字串中第一次出現處的索引

* int indexof(string str);獲取指定字串在此字串中第一次出現處的索引

* int indexof(int ch, int fromindex);獲取指定字元在此字串中從指定位置後第一次出現處的索引

* int indexof(string str, int fromindex);獲取指定字串在此字串中從指定位置後第一次出現處的索引

* string substring(int start);從指定位置開始擷取字串,預設到結尾位置

* string substring(int start, int end);從start位置開始擷取字串,到end位置結束。不包括end位置的字元

* */

public class stringdemo3

}

/*

* 字串的遍歷

*/public class stringdemo4

}}

/*

* string類的轉換功能

* byte getbytes():將乙個字串轉換位元組陣列

* char tochararray():(重點方法):將乙個字串轉換成字元陣列

* static string valueof(char chs):將字元陣列轉換成字串

* static string valueof(int i):將int型別的資料轉換字串

* 注意:string類中的valueof方法可以將任何資料型別轉換成string

* string tolowercase():將字串轉換成小寫

* string touppercase():將字串轉換成大寫

* string concat(string str):字串拼接功能

*注意:

* 陣列中有沒有length()? 字串中有沒有length()?

* length:陣列長度屬性 :陣列中不存在這個方法

* 字串中有length():返回字串長度

*/public class stringdemo5

// char tochararray():(重點方法):將乙個字串轉換成字元陣列

char b2 = str.tochararray();

for (char bb : b2)

// string tolowercase():將字串轉換成小寫

system.out.println(str2.tolowercase());

// string touppercase():將字串轉換成大寫

system.out.println(str2.touppercase());

// string concat(string str):字串拼接功能

system.out.println(str.concat(str2));

}}

/*

* string類的其他功能

* 替換功能:

* string replace(char old,char new):

* string replace(string old,string new):

* * 去除字串兩空格(去前後兩端空格):

* string trim():

* * 按字典順序比較兩個字串

* int compareto(string str):

* int comparetoignorecase(string str):

* */

public class stringdemo6

}

js jq 的常用功能

js的新增屬性和移除屬性 新增 document.getelementbyid down setattribute disabled true 移除 document.getelementbyid up removeattribute disabled jq的新增屬性和移除屬性 新增 up attr...

idea的常用功能

快捷鍵的使用常常能起到事半功倍的效果,話不多說,看下面常用的快捷方式吧。熟練使用絕對大大提高開發速度。一,搜素快捷鍵 1.ctrl n搜素類,相當於eclipse的ctrl shift r 2.ctrl shift n 搜尋所有檔案,包含類,xml,js,web 等 3.ctrl h 檢視類的繼承關...

vim的常用功能

vim三種模式 1.命令模式 1 調整vim工作模式 在vim程式中 set 調整引數 示例 set nu 行號新增 set nonu 取消行號 set mouse a 新增滑鼠選擇 set cursorline行線顯示 注 在vim程式中設定的vim工作方式是臨時的,在vim關閉後會還原,如果要永...