Math class
Package Box;import java.util.arraylist;import Java.util.collections;import java.util.List; Public classTestbox { Public Static voidMain (string[] args) {//Eight packaging categories /*The integer i=5;//opens up a memory space in the stack (basic data type), integer n = new Integer (5), and//opens a memory space (object) int m = 5 with new in the heap; byte B = new byte ("1"); Boolean Bool=new Boolean (true); Long lon = new Long (1000); Short s = new Short ("5"); Double d = new double (100.0); float f = new float (66.00); Character C = new Character (' C '); */ //Math classSystem. out. println (Math.ceil (6.9));//Rounding upSystem. out. println (Math.floor (6.9));//downwardSystem. out. println (Math.Round (6.3));//RoundingSystem. out. println (Math.pow (8,3));//The power of seeking a second DoubleR =5.5; Doubles = Math.pi*math.pow (R,2); System. out. println (s); //Generate random numberslist<integer> list =NewArraylist<> ( -); for(inti =0; I < -; i++) {list.add (i); } collections.shuffle (list);//a method of collections tool class shuffle ()List.foreach (System. out::p rintln); }}
Result diagram:
String Class
Package Box; Public classStringtest { Public Static voidMain (string[] args) {String s="ABFD";//string is not a basic data type, it is a very special classString S1 =NewString ("ASSD"); //trim () Remove the string "both ends" of the space (the middle of the cannot be removed)System. out. println (S.length ()); System. out. println (S.trim (). Length ()); //substring: Intercepting stringsString s2 ="one more bottle."; System. out. println (S2.substring (2)); System. out. println (S2.substring (1,2)); //indexOf: Finds the index of the first letter of the substring in the current character and returns 1 if it is not foundString s3 ="123ab45ab67"; System. out. println (S3.indexof ("AB")); System. out. println (S3.indexof ( the));//97 for ASCLL codeSystem. out. println (S3.indexof ("AB",5)); //finds the last index position of the string in the current stringString S4 ="123321"; System. out. println (S4.lastindexof ("2")); //replace replaces the specified characterString S5 ="a b c D"; System. out. println (S5.replace (" ","")); System. out. println ("*****************************************"); //Split splits the string in the specified format, returning an array of stringsString s6 ="a b c D EF"; String []s7= S6.split (" "); for(String str:s7) {System. out. println (str); } String S8="ABCDBDFG"; System. out. println (S8.charat (1));//more than will error }}
Result diagram:
Stingbuffer and StringBuilder (note the difference between the two uses)
Package Box;//string is a constant StringBuffer is a variable (frequent stitching required) Public classStringbuffertest { Public Static voidMain (string[] args) {StringBuffer sb=NewStringBuffer ("ABC");//High SafetySb.append ("de"); Sb.append ("FG"); String S9=sb.tostring (); System. out. println (S9); StringBuilder SB1=NewStringBuilder ("Abd");//Fast but low security (can//own locking)Sb1.append ("de"); String S10=sb1.tostring (); System. out. println (S10); }}
Result diagram:
Radom class
Public classRandomtest { Public Static voidMain (string[] args) {random random=NewRandom (); intN=random.nextint (Ten); System. out. println (n); BooleanBOOL=Random.nextboolean (); System. out. println (BOOL); for(inti =0;i<Ten; i++){ DoubleN1 =random.nextdouble (); System. out. println (n1*9+1); } for(inti =0;i<Ten; i++) {Boolean B1=Random.nextboolean (); System. out. println (B1); } }}
Result diagram:
Java Learning Record (Supplementary seven: some tool classes)