常見類的方法 一

2021-10-03 19:37:11 字數 3298 閱讀 5902

object類中的下列方法

public boolean equals(object obj)

其他某個物件是否與此物件「相等」,一般是位址值

public final class getclass()

獲取物件的真實類的全名稱。

public int hashcode()

返回該物件的雜湊碼值。預設情況下,該方法會根據物件的位址來計算

public string tostring()

返回該物件的字串表示,即位址值

string類中的下列方法
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)

把乙個字元陣列從index下標處開始的count個字元轉換成字串

public string(string original)

把乙個字串轉換成乙個字串

public boolean equals(object obj)

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

public boolean equalsignorecase(string str)

比較字串是否相等,比較的是內容,不去分大小寫

public boolean contains(string str)

判斷乙個字串是否包含str字串

public boolean startswith(string str)

判斷乙個字串是否一str這個字串開始

public boolean endswith(string str)

判斷乙個字串是否以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)

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

順帶提一下lastindexof系列,和上面的一樣只不過從後面第乙個

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型別的資料轉成字串。

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)

將指定字串進行互換

public string trim()

去除兩端空格

public int compareto(string str)

從第乙個字母進行減法運算,返回的就是這個減法的結果

如果前面幾個字母一樣,會根據兩個字串的長度進行減法運算,返回的就是這個減法的結果

如果連個字串一摸一樣,返回的就是0

public int comparetoignorecase(string str)

跟上面一樣 只是忽略大小寫的比較

stringbuffer(stringbuilder)類中的下列方法
public int capacity()

返回當前容量,理論值

public int length()

返回長度(字元數) 實際值

可以把任意型別資料新增到字串緩衝區裡面,並返回字串緩衝區本身

public stringbuffer insert(int offset,string str)

指定位置把任意型別的資料插入到字串緩衝區裡面,並返回字串緩衝區本身

public stringbuffer deletecharat(int index)

刪除指定位置的字元,並返回本身

public stringbuffer delete(int start,int end)

刪除從指定位置開始指定位置結束的內容,並返回本身

public stringbuffer replace(int start,int end,string str)

從start開始到end用str替換

public stringbuffer reverse()

字串反轉

public string substring(int start)

從指定位置擷取到末尾

public string substring(int start,int end)

取從指定位置開始到結束位置,包括開始位置,不包括結束位置

聚類與常見聚類方法

2.層次聚類 hiecarchical clustering 3.密度聚類 density based clustering 4.參考 k均值演算法是屬於劃分的聚類方法,k均值演算法將樣本分為k類,是通過最小化簇內距離 平方誤差 來實現的。e i 1n x c i x ui 22e sum n su...

String類的常見方法整理

判斷 boolean equals object obj 比較內容是否相等 boolean equalsignorecase string str 比較內容是否相等,忽略大小寫 boolean contains string str 判斷字串是否包含字串str boolean startswith ...

Object類的常見方法總結

object類是比較特殊的類,它是所有類的父類。主要提供了11個方法 jdk 1.8為例 native方法,用於返回當前執行時物件的class物件,使用final關鍵字修飾,子類不允許進行重寫 public final native classgetclass native方法,用於返回物件的雜湊碼...