Java中使用頻率較高的函式

2021-08-03 09:57:50 字數 3669 閱讀 1988

1.常用數學函式

math.abs(±7.5);            //返回絕對值結果:7.5math.copysign(7, -5);      //返回第乙個引數的絕對值,第二個引數的符號結果:-7math.signum(-7.5);         //正數返回1.0,負數返回-1.0,0返回0結果:-1.0math.exp(0);               //e的0次冪結果:1math.expm1(1);             //e的-1次冪結果:-emath.log(e);               //以e為底的對數結果:1math.ceil(-7.5);           //返回最近的且大於這個數的整數結果:-7math.floor(-7.5);          //返回最近的且小於這個數的整數結果:-8math.rint(7.4);            //返回最近的整數結果:7math.rint(7.5);            //若是中間數則取偶數結果:8
math.hypot(3, 4); //返回兩數和的平方根結果:5

math.sqrt(9); //返回該數的平方根結果:3

math.cbrt(27.0); //返回該數的立方根結果:3

math.max(7, 5); //返回7、5中較大的那個數結果:7

math.min(7, 5); //返回7、5中較小的那個數結果:5

math.pow(2, 3); //返回2的3次冪結果:8

math.random(); //產生隨機數

2.string相關函式

charat():

char ch;

ch=」abc」.charat(1); //返回第1個字元結果:a

substring():

string s1 ="1234567890abcdefgh";

s1 = s1.substring(10); //返回從第10個數到末尾的子串結果:abcdefghstring s1 ="1234567890abcdefgh";

s1 = s1.substring(10,11); //返回從第10個子串結果:a

concat():

string s="welcome to ";

string t=s.concat("nanjing"); //連線兩個字串結果:welcome to nanjing

replace():

string m="hello";

string n=m.replace('l', 'h');

system.out.println(n); //將字串中所有字元'l'替換成'h'結果:hehho

tolowercase()/touppercase():

string m="hello";

string n=m.tolowercase();

system.out.println(n); //將字串中所有字元變成小寫結果:hellostring i=m.touppercase();

system.out.println(i); //將字串中所有字元變成大寫結果:hello

length():

char chars=;

string s=new string(chars);

int len=s.length();

system.out.println(len); //獲取字串的長度結果:3

valueof():

char chars=;

string value=string.valueof(chars);

system.out.println(value); //轉化為字串結果:abc

trim():

string chars=" abcdefg ";

int len1=chars.length();

system.out.println(chars+" 長度為:"+len1);

//返回原字串和其長度結果: abcdefg 長度為:9string value=chars.trim();

int len2=value.length();

system.out.println(value+" 長度為:"+len2);

//返回去掉空格後的字串和其長度結果:abcdefg 長度為:7

getchars():

string s="this is a demo of the getchars method";

char buf=new char[4];

s.getchars(10,14,buf,0);

//返回原字串從第10位到第14位的子串,存至陣列buf,字串前偏移量為0

system.out.println(buf);//結果:demo

equals():

string str1 = new string("hello");

string str2 = new string("hello");

system.out.println("str1和str2是否相等?"+str1.equals(str2));

//判斷兩個字串是否相等結果:str1和str2是否相等?true

Intellij Idea使用頻率較高的幾個快捷鍵

自動補全引數定義 ctrl alt v 執行斷點expression alt f8 選擇具體的方法以斷點步入 shift f7 智慧型操作 alt enter 開啟最近檔案 ctrl e 開啟資料夾 double shift後,輸入 資料夾名 補全行層分號 ctrl shift enter 調出歷史...

Ubuntu頻率較高的操作

由於 ubuntu 是基於 debian 的 linux 作業系統,在預設的情況下,是沒有超級使用者 superuser,root 的,但有些系統操作必須有超級使用者的許可權才能進行,如安裝軟體包。在其他 linux 作業系統 如 fedora 下,可以使用 su 切換到超級使用者。當輸入 su 命...

2006 年使用頻率比較高的幾款軟體

這篇 blog 算是對去年 2005 年度我最喜歡的幾個軟體 的回顧吧。greatnews rss 閱讀工具 旺旺 im 工具 工作中必備的工具。作為一款面向電子商務的 im 工具,旺旺還是很稱職的。im 工具的發展就像手機一樣,乙個功能非常繁複的產品未必能讓所有人喜歡,相反,能滿足大部分普通使用者...