常用類方法 排序

2021-08-30 02:30:42 字數 2747 閱讀 7189

object為所有類的頂層父類

hashcode()方法

預設情況下將物件的位址值用雜湊演算法轉換為乙個整數值

int hashcode () 返回該物件的雜湊碼值
getclass()方法

返回此 object 的執行時類。

public final class getclass()
tostring()方法

返回該物件的字串表示。

public string tostring()
預設情況下的資料對我們來說沒有意義,一般建議重寫該方法。

一般是將該類的所有的成員變數組成返回即可。

equals()方法

預設比較兩個物件的位址值

可以重寫比較兩個成員變數的值是否相等.

a.equals(b);
構造方法public string()空構造

public string(byte bytes把位元組陣列轉成字串

public string(byte bytes,int index,int length)

把位元組陣列的一部分轉成字串(index:表示的是從第幾個索引開始, length表示的是長度)

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

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

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

判斷功能

public boolean equals(object obj)

比較字串的內容是否相同,區分大小寫

public boolean equalsignorecase(string str)

比較字串的內容是否相同,忽略大小寫

public boolean contains(string str)

判斷字串中是否包含傳遞進來的字串

public boolean startswith(string str)

判斷字串是否以傳遞進來的字串開頭

public boolean endswith(string str)

判斷字串是否以傳遞進來的字串結尾

public boolean isempty()

判斷字串的內容是否為空串""。

獲取功能

public int length()

獲取字串的長度。

public char charat(int index)

獲取指定索引位置的字元

public int indexof(int ch)

返回指定字元在此字串中第一次出現處的索引。

public int indexof(string str)

返回指定字串在此字串中第一次出現處的索引。

public int indexof(int ch,int fromindex)

返回指定字元在此字串中從指定位置後第一次出現處的索引。public int indexof(string str,int fromindex

返回指定字串在此字串中從指定位置後第一次出現處的索引。public string substring(int start)

從指定位置開始擷取字串,預設到末尾。

public string substring(int start,int end)

從指定位置開始到指定位置結束擷取字串

轉換功能

public byte getbytes()

把字串轉換為位元組陣列。

public char tochararray()

把字串轉換為字元陣列。

public static string valueof(char chs)

把字元陣列轉成字串。

public static string valueof(int i)

把int型別的資料轉成字串。

注意:string類的valueof方法可以把任意型別的資料轉成字串。public string tolowercase()

把字串轉成小寫。

public string touppercase()

把字串轉成大寫。

public string concat(string str)

把字串拼接。

替換功能

public string replace(char old,char new)

將指定字元進行互換

public string replace(string old,string new)

將指定字串進行互換

選擇排序

選擇乙個數,和之後的數字進行比較

從0索引開始,依次和後面元素比較,小的往前放,第一次完畢,最小值出現在了最小索引處。

氣泡排序

相鄰元素兩兩比較,大的往後放,第一次完畢,最大值出現在了最大索引處

Math類常用方法

名稱說明 abs已過載。返回指定數字的絕對值。acos 返回余弦值為指定數字的角度。asin 返回正弦值為指定數字的角度。atan 返回正切值為指定數字的角度。atan2 返回正切值為兩個指定數字的商的角度。bigmul 生成兩個 32 位數字的完整乘積。ceiling 已過載。返回大於或等於指定數...

Graphics類常用方法

名稱 說明 drawarc 畫弧。drawbezier畫立體的貝爾塞曲線。drawbeziers 畫連續立體的貝爾塞曲線。drawclosedcurve 畫閉合曲線。drawcurve 畫曲線。drawellipse畫橢圓。drawimage 畫影象。drawline 畫線。drawpath 通過路...

String 類常用方法

字串 就是由多個字元組成的一串陣列 一旦被複製,就不能被改變 public class stringdemo string s2 new string bys system.out.println s2 s2 system.out.println s2.length s2.length 5 syst...