12. Common classes:
String-related classes:
Strings are arranged in alphabetical order, with a ratio of characters and length.
String class:
The string class is a reference, and the data in the String constant is unchangeable. Even if it is changed, the string reference is directed to another space.
During the loading period, all the string constants are placed in the constant pool in advance as objects before the main method.
Reference to heap:
String STR = new string ("hello"); the new object is directly added without checking the constant pool (this code generates two string objects, which are generated in the constant pool in advance during loading, then a new object is stored in the heap .)
Reference to the constant pool:
String STR = "hello"; this code will first look for an object in the constant pool, and its reference will direct to that object. If it does not exist, it will re-divide the space to create objects.
Stringbuffer class:
This class is variable. It does not inherit the string. If it is used, it cannot be directly assigned a string that can only be obtained through the constructor new.
Stringbuffer sb = new stringbuffer ("hello ");
SB. append ("world ");
Its link character is not a + sign, but an append ();
You can call its tostring method to convert it into a string object.
The only advantage over string is the string link action, which does not generate new string objects in memory.
Stringbuilder class:
It is the same as the stringbuffer class.
The difference is that stringbuffer is thread-safe, while stringbuilder is insecure.
Date-related classes:
Date class:
The current function of date is to get the current time and print the output in the required format.
Date = new date ();
Dateformat abstract class and simpledateformat class:
Dateformat is an abstract class that cannot be real-listed, but it provides a large number of static methods to return a specific subclass. We can format the date and time in an inaccessible way.
The getdateinstance () method of the dateformat class can return a format for the date according to the default or region.
After obtaining the specific subclass, we can call the format () method of the specific subclass to format the datetime in a predefined manner.
The calendar ner abstract class and the gregoriancalender class;
The calender class is abstract and cannot be instantiated. Its unique subclass is the gregoeiancalender class, so its static method getinstance () is to return a gregoriancalender object.
Calender Cal = calender. getinstance (); this is the design mode.
Gregoriancalender day = new gregoriancalender (1949,9, 1 );
It should be noted that the month is from 0 or remember, for example, 12 + 1 is December, and the week starts from Sunday, for example, 1 is Sunday, and 3 is week 2.
Packaging and automatic packing and unpacking:
A packaging class encapsulates attributes of a large number of basic classes (such as the maximum and minimum values) and a large number of methods for converting basic types.
In section 8, the data type corresponds to only int (integer) and char (character) Packaging classes. Other packaging classes change the initial letter to uppercase.
The number class includes struct value (), intvalue (), doublevalue (), and other methods. using these methods, the corresponding basic data type is returned.
Parse... (String s) method to convert a string to the corresponding basic data type.
Conversion between basic types and packaging objects:
Basic conversion objects: automatic packing and automatic unpacking.
Conversion of packaging objects: calling the packaging class... Value method.
Convert a packaging class object to a string: Call the tostring method of the packaging class object.
String to packaging Class Object: Call the tostring constructor with parameters of the packaging class object.
String Conversion: Call the parse of the packaging class... Method.
Basic conversion string: Call the tostring method with parameters in the packaging class. Alternatively, you can directly use a string to link an empty string. String S1 = variable name + "";
Regular Expression RegEx:
Any string is a regular expression.
(|) Group, which can be placed before or after a vertical line, and can be separated by multiple vertical lines;
\ Escape ,(\\?);
* Matches the previous subexpression zero or multiple times;
+ Match the previous subexpression once or multiple times;
? Match the previous subexpression zero or one time;
The number of times the previous rule {n} is allowed to appear;
{N,} appears at least N times, not limited;
{N, m} At Least n times at most m times;
[ABC] matches an ABC;
[A-F] matches all characters from A to F.
[^ 0-9] The value ranges from 0 to 9.
Property file:
Key-value (Kv pair)
Key is the key value is the value, and the number of elements is composed of the key and value. They always appear together.