Practical class
Packaging class Construction
Conversion of basic data types to basic types
Method One
Boxing: Converting the basic data type to the corresponding object type
Role:
1. Make the necessary conversions when you need to use the object type data
For example, in a collection frame
2, the conversion is completed after the corresponding properties and methods, convenient operation
Public type (type value)
Integer intvalue = new integer (21);
Long longvalue = new Long (21L);
Character charvalue = new Character (' V ');
First Kind
Integer intvalue = new integer (21);//boxed data produces corresponding properties and methods
System.out.println (Intvalue);
int a = intvalue;//unboxing
System.out.println (a);
The second Kind
Integer integer = new Integer ("015");
System.out.println (integer);
int b = integer;
System.out.println (b);
Third Kind
Integer integer2 = integer. valueOf (23);//Boxing
System. out. println (INTEGER2);
int c = integer2.intvalue ();//Unpacking
System. out. println (c);
Fourth type
Integer integer3= 3;//Boxing
int d = Integer3; Unpacking
Conversion of string to base type
Convert strings to basic data types
int i5 = integer.parseint ("213");
SYSTEM.OUT.PRINTLN (i5);
float f = float.parsefloat ("123");
System.out.println (f);
Double I6 = double.parsedouble ("567");
System.out.println (I6);
Boolean i8 = Boolean.parseboolean ("0");
System.out.println (i8);
Basic data types are converted to string types
int i7 = 123;
String I9 = integer.tostring (i7);
System.out.println (I9);
The second Kind
String s = 123+ "";//Direct conversion
System. out. println (s);
Math class
provides two static constants E and PI
Math class
int num1 = Math. Max (23, 20);//Larger
System. out. println (NUM1);
double num2 = Math. POW (2, 3);//2 3-Time Square
System. out. println (num2);
double num3 = Math. sqrt (4);//Open square
System. out. println (NUM3);
int num4 = -6;//
int abs = Math. ABS (NUM4);//Absolute value
System. out. println (ABS);
double angle = (Math. PI/2);
double sin = Math. Sin (angle);//sine
System. out. println (sin);
double cos = Math. Cos (angle);//
System. out. println (COS);
double tan = Math. Tan (angle);
System. out. println (tan);
Double ASIN = Math. ASIN (angle);
Random method
Returns a random number from 0 to 1 (including 0 less than 1)
Outputs a random number from 1 to 10
int random = (int) (Math. Random() *10+1);
System. out. println (random);
Random
int random = (int) (Math. Random() *10+1);
System. out. println (random);
int check = Math. Random () >0.5?1:0;
System. out. println (check);
int random2 = (int) (Math. Random() *6+5);
System. out. println (RANDOM2);
Trim returns a copy of the string, ignoring leading and trailing blanks.
Substring intercept
IndexOf Find
Replace returns a new string, which is newChar obtained by replacing all occurrences of this string oldChar .
Replace (char OldChar, char Newchar)
Returns a new string that is obtained by replacing all OldChar that appear in this string with Newchar.
toUpperCase ()
Converts all characters in this String to uppercase using the rules of the default locale.
StringBuffer |
Append (Boolean B) Appends the string representation of a Boolean parameter to the sequence. |
Various practical classes