Enumeration: refers to a type consisting of a fixed set of constants (note: int type, double type, boolean type, float type cannot be written). In order to avoid giving the value is wrong
Commonly used JAVA APIs include: (java.lang) Enum, wrapper class, Math, String, StringBuffer, System, (java.util, java.io, java.sql)
Wrapper class: converts basic data into objects
Each primitive type has a corresponding wrapper class in the java.lang package
Function: <1> Provide a series of practical methods <2> Collection does not allow to store basic data types, when storing numbers, use packaging type
Therefore, the wrapper classes have some construction methods, and the corresponding basic data types are used as parameters.
E.g:
int i=9;
Integer i1=new Integer( i ); ----> turn the basic data type into a wrapper class
Double d=new Double( i );
All wrapper classes except Character have constructors that take strings as parameters
E.g:
Integer i1=new Integer( "9" ); ----> Note: 1. When the parameter of the Number wrapper class constructor is of type String, the string cannot be null, and the actual parameter of the parameter must be convertible into the corresponding type, not convertible
Boolean b=new Boolean("TruE"); The corresponding string, such as "I", is the actual parameter 2. The actual parameter of Boolean, no matter what the size, as long as it is true, the others are false, such as " stain”
Common methods of wrapper classes:
1>***Value(): The wrapper class is converted into a basic type (corresponding to the method of Number type conversion)
2>valueOf(): 1. Convert the base class to a wrapper class Integer i=Integer.valueOf(21);
2. In addition to the Character class, the string is converted into a wrapper class Integer i=Integer.valueOf("21");
3>toString(): Return the wrapper object in the form of a string, and convert the basic type into a string
String sex=Character.toString('男');
String num=Integer.toString(44);
Or: String sex='male'+" ";
String num=25+" "; ---> or directly add an empty string
4>parse***(): Convert the string to a basic type and convert it to the corresponding basic data type data (except Character)
E.g:
int num = Integer.parseInt("36");
boolean b=Boolean.parseBoolean("false");
Boxing and unboxing: automatic conversion of primitive types and wrapper classes
Boxing: Convert the basic type to the object of the wrapper class ----> Small becomes larger
Unboxing: the wrapper class is converted to an object of a primitive type ----> bigger becomes smaller
Note: The wrapper class is not used to replace the basic data type, it is used when the basic data type needs to be represented by an object
scenes to be used:
1> You can use basic data types in the defined classes
2> String conversion of basic data types
3> The mapping in the framework requires a wrapper class
Math class -----> The commonly used random class: Math.random() method, which generates floating-point numbers between 0 (inclusive) and 1 (exclusive)
Random class: equivalent to a random number generator, and then call its method
Steps for usage:
1> Create a Random object
Random rand=new Random();
2> call its method
nextInt(); The random number without parameters is a random number generated in the range of int
nextInt(int a); The random number with parameter is to generate the specified parameter range number
One of the constructors in the Random class is a constructor with parameters. When instantiated, the actual parameters are used as seeds to generate random numbers; the other is a constructor without parameters.
Then you can use time milliseconds as the actual parameter of the constructor, so that the random number generated will be better