I. List of packing classes
Basic data types |
Packing class |
Byte |
Byte |
Short |
Short |
Int |
Integer |
Boolean |
Boolean |
Char |
Character |
Long |
Long |
Float |
Float |
Double |
Double |
1) in these eight class names, except for the integer and character classes, the class name of the other six classes is the same as the base data type, except that the first letter of the class name is capitalized.
2) for the wrapper class, the use of these classes consists of two main types:
A, as the basic data type corresponding to the class type exists, convenient to involve the operation of the object.
b, contains the relevant attributes for each basic data type, such as maximum, minimum, and related methods of operation.
3) Since the use of eight packaging classes is similar, the following is the most commonly used integer class as an example of the actual use of packaging classes.
1. Implement conversions between int and integer classes:
int n = 10;
Integer a = new integer (n); int to Integer (boxing)
Integer B = integer.valueof (n); int to Integer (boxing)
int k = A.intvalue (); Integer to int (unboxing)
2, integer internal common methods
int n = integer.parseint ("123"); The string is converted to int, and if the argument is not a numeric string, an exception numberformatexception occurs.
int k = Integer.parseint ("123", 16); The parameter can be two, and the following represents the binary you want to convert to.
String s = integer.tostring (123); Turn the number 123 into the string "123".
String S1 = integer.tostring (123,16); Converts the number 123 into a string, in 16 binary form.
Ii. Type of date
Types under the Date:java.util package
Get current system time:
1) Date now = new Date ();//Gets the current system time in the date format.
Method:
GetTime (); Gets the number of milliseconds, long type
SetTime (long time);
2) System.currenttimemillis (); Gets the number of milliseconds from the January 1, 1970 Point in time
Third, date formatting type
SimpleDateFormat: types under the Java.text package
Define the format:
1): Can format date, change date to string
Format (date date)//String type returned
eg
Date date = new Date ();
SimpleDateFormat SimpleDateFormat = new SimpleDateFormat ("Yyyy-mm-dd");
String s = simpledateformat (date);
2): You can convert a string into a date
Parse (String date)//date type returned
Date date = Simpledateformat.parse ("1999-1-1");
Java wrapper classes and other classes