String類主要方法的使用

2021-07-24 18:40:41 字數 638 閱讀 2764

1、獲取長度 *.length();//這與陣列中的獲取長度不同,*.length;

2、比較字串(1) equals() //判斷內容是否相同

(2)compareto() //判斷字串的大小關係

(3)comparetoignorecase(string int) //在比較時忽略字母大小寫

(4)== //判斷內容與位址是否相同

(5)equalsignorecase() //忽略大小寫的情況下判斷內容是否相同

如果想對字串中的部分內容是否相同進行比較,可以用

(6)reagionmatches() //有兩種 public boolean regionmatches(int toffset, string other,int ooffset,int len);表示如果string物件的乙個子字串與引數other的乙個子字串是相同的字串行,則為true.要比較的string 物件的字串從索引toffset開始,other的字串從索引ooffset開始,長度為len。

public boolean reagionmatches(boolean ignorecase,int toffset,string other,int ooffset,int len);//用布林型別的引數指明兩個字串的比較是否對大小寫敏感。

String類 主要常用方法解析

package com.string.demo public class demo1 char c str.charat 1 根據索引獲取單個字元 system.out.println c system.out.println str 這是乙個字串,你懂個錘子 string strs2 str.sp...

File類主要方法使用

相對路徑 不帶碟符的路徑是相對路徑 當前目錄 獲取父類路徑 22112 desktop 絕對路徑 完整的路徑名稱 帶有碟符 windos c linux system.out.println file.getabsolutepath 得到當前file絕對路徑 boolean exists 判斷當前路...

String類方法使用整理

個人理解就是用regex字串去分割string物件,並將每一段放入string陣列中,例如最簡單的 test1 test public void splittest1 輸出如下,很明顯此時split陣列為 陣列長度為5 test2 這一種特殊情況要注意,在劍指 offer 58 i.翻轉單詞順序中有...