string string2=「123456」;system.out.println(string.charat(1)); //2
string s1=「w」;string s2=「w」;
string s3=「l」;
system.out.println(s1.compareto(s2));//在相同的情況下返回0
system.out.println(s1.compareto(s3));//不同的情況下返回差值 這個是11
注:在學習到集合linkedlist時會用到
string s1=「wang」;string s2=「shaoye」;
system.out.println(s1.concat(s2));//wangshaoye
string s1=「wang」;boolean b=s1.endswith(「g」);
system.out.println(b);//true
boolean b2=s1.startswith(「z」);
system.out.println(b2);//false
string s1=「wang」;string s2=「li」;
boolean b=s1.equals(s2);
system.out.println(b);//false
string s1=「wang」;byte bytes = s1.getbytes();
for (byte b : bytes)
string s1=「wang」;int hashcode = s1.hashcode();
system.out.println(hashcode);//3641859
string s1=「xiaoniux」;int index = s1.indexof(「x」);
指定字元第一次出現的位置用int表示出來
int indexof = s1.indexof(「x」,2);
指定字元從第2次出現的位置用int表現出來
system.out.println(index);//0
system.out.println(indexof);//7
string s1=「xiaoniuxiyouxi」;int lastindexof = s1.lastindexof(「x」);
system.out.println(lastindexof);//12
//指定字元最後一次出現的位置
int lastindexof2 = s1.lastindexof(「o」, 12);
system.out.println(lastindexof2);//10
//從指定位置開始,反向搜尋這個字元第一次出現的位置,我是這麼理解的
string s1=「xiaoniuxiyouxi」;boolean empty = s1.isempty();
system.out.println(empty);//false
string s1=「xiaoniuxiyouxi」;int length = s1.length();
system.out.println(length);//14
string s1=「15822221234」;string regex="[1][3578]\d";
boolean matches = s1.matches(regex);
system.out.println(matches);//true
替換
string s1=「******」;string replace = s1.replace(『x』, 『y』);
system.out.println(replace);//yyyyyy
string s2=「www.xx.com」;
string replaceall = s2.replaceall(「x」,「n1」);
//這個repalceall方法是把符合第乙個引數的值全部替換為第二個引數
system.out.println(replaceall);
string s2=「2121212121」;string split = s2.split(「1」);
system.out.println(arrays.tostring(split));//[2, 2, 2, 2, 2]
string s1=「sunwukong」;string substring = s1.substring(3,5);
system.out.println(substring);
java math類方法摘要
math類包含基本的數字操作,如指數 對數 平方根和三角函式。1 sqrt 返回正確捨入的double值的正平方根。特殊情況是 2 ceil 是不小於他的最小整數。特殊情況是 3 floor 返回不大於他的最大整數。特殊情況是 4 rint 返回其值最接近引數並且是整數的double值。如果兩個整數...
Math類常用方法
名稱說明 abs已過載。返回指定數字的絕對值。acos 返回余弦值為指定數字的角度。asin 返回正弦值為指定數字的角度。atan 返回正切值為指定數字的角度。atan2 返回正切值為兩個指定數字的商的角度。bigmul 生成兩個 32 位數字的完整乘積。ceiling 已過載。返回大於或等於指定數...
Graphics類常用方法
名稱 說明 drawarc 畫弧。drawbezier畫立體的貝爾塞曲線。drawbeziers 畫連續立體的貝爾塞曲線。drawclosedcurve 畫閉合曲線。drawcurve 畫曲線。drawellipse畫橢圓。drawimage 畫影象。drawline 畫線。drawpath 通過路...