相關方法的使用

2022-07-21 14:15:27 字數 1738 閱讀 9731

beanutils.copyproperties("要轉換的類", "轉換後的類");  

substring的用法,兩個引數的用法,(起始位置,終止位置),如果確定了起始位置和終止位置的數,可以配置indexof()使用

例子

stringbuilder s = new stringbuilder("swwq--2.44");

string s1 = s.substring(s.indexof("q"), s.indexof("2"));

system.out.println(s1);

hootool的相關用法

dateutil.parse(),兩個引數第乙個為時間,第二個為想要呈現的時間格式

例子

datetime date = dateutil.parse(dateutil.now(), "yyyymmddhhmm");

system.out.println(date);

fileutil.readstring(),兩個引數,第乙個為檔案位址,第二個為編碼格式」utf-8「,」gbk「等等,返回字串

例子

string s2 = fileutil.readstring("c:\\users\\administrator\\desktop\\spring.txt", "utf-8");

system.out.println(s2);

file.separator代表系統目錄的分隔符,不同的系統中顯示不同,/或者\這種,也有可能是//等,

為了解決跨平台性問題

windows下

file file1 = new file ("c:\tmp\test.txt");

linux下

file file2 = new file ("/tmp/test.txt");

如果要考慮跨平台,則最好是這麼寫:

file myfile = new file("c:" + file.separator + "tmp" + file.separator, "test.txt");

jsonarray.tolist()方法,引數為類名.class,返回list集合,json型別的陣列轉換為集合

例子public class user{

string name;

int age;

strutil的相關用法

strutil.isblank();括號內引數為string型別的資料,返回boolean型別,該方法判斷字元是否為空白,包括不可見字元空格

strutil.isempty()跟上述方法類似,不同的是不包括空格,只包含null,兩者的區別是如果乙個頁面有空格,isempty還是認為什麼都沒有,返回true,而isblank認為有資料,即空格型別的資料。返回false。判斷檔案用isempty方法

strutil.hasblank();括號內引數為string型別的資料,返回boolean型別,該方法判斷字串是否包含空格。

strutil.startwith();兩個引數,第乙個為字串名稱,第二個為字串。返回boolean型別。

strutil.removesuffix(),去掉指定的字尾,strutil。removeprefix()去掉指定的字首

例子

stringbuilder s = new stringbuilder("swwq--2.44");
string s2 = strutil.removesuffix(s, "2.4");

system.out.println(s2);

Python set 相關方法的使用

描述 intersection 方法用於返回兩個或更多集合中都包含的元素,即交集。語法 intersection 方法語法 set intersection set1,set2 etc 引數 set1 必需,要查詢相同元素的集合 set2 可選,其他要查詢相同元素的集合,可以多個,多個使用逗號 隔開...

Collection集合的相關方法與使用

常用基本方法 1.新增 boolean add object obj 新增 boolean addall collection coll 新增集合 2.刪除 boolean remove ooject obj 刪除 boolean remove collection coll 刪除集合 void c...

Golang sync 包的相關使用方法

desc go sync 包的使用方法,sync.mutex,sync.rmutex,sync.once,sync.cond,sync.waitgroup 儘管 golang 推薦通過 channel 進行通訊和同步,但在實際開發中 sync 包用得也非常的多。另外 sync 下還有乙個 atomi...