JAVA11 Regular Expressions
L Concept
- is a string
- Meet a certain rule
- QQ number Check
[1-9] [0-9] [4,9]
- Check if certain characters are compliant such as whether the user name is compliant
- One [] represents one or more characters
- It's too complicated to solve some problems with string
L Matching Rules
- Character X
A) the content that needs to be matched is a
- Character \ \
a) representative \
b) is an escape character
- \ t tab
- \ n line break add a blank line
- \ r carriage return cursor to the header of the next line
- [ABC] represents a range of characters
- [^ABC] represents the inverse of a range that is not ABC to match
- [A-za-z] any one letter
- [0-9] any one number
- [Z-A-Z _ 0-9] Letter underline and number match
- \d Representative Number 0-9
- \w the letter underscore and the number match
- ^ Represents the beginning of the line
A) ^[abc][0-9]$ needs to match the content starting from [ABC] this position is equivalent to the left double quotation mark
- $ represents the end of the line
A) ^[abc][0-9]$ need to match the content to end with [0-9] This position equivalent to the right double quotation mark
- \b Word boundaries
Requires a non-word character alphanumeric underscore on both sides of a character
- X? Represents x once or once or no
- X * Represents 0 or more occurrences
- X + represents one or more occurrences
- X{n} represents n times
- X{n,} represents the presence of at least n times
- X{n,m} represents the presence of at least n times but not exceeding m times
L Use
- Matches of the String class
The return value is a Boolean
"ABC". Matches ("[A]")
- Method of the String class split
Return value is string[]
Use a rule to cut a string
"ABC". Split ("a");
- Method ReplaceAll of the String class
The return value is a string
Change strings by rule
"Abc0123". Reaplceall ("[\\d]", "#")
Replace all numbers with #
- “ . ” Represents any character
- "\\d+" integer
- "\\d+\\.\\d+" positive decimals
- "-\\d+" negative integer
- "-\\d+\\.\\d+" negative decimals
- "\\d+\\.\d{2}" retains a positive number of two decimal places
- "\\d+\\.\d{1,3}" retains a positive number of 1-3 decimal places
Date class
L Overview
- Represents a specific moment accurate to milliseconds
- To implement the interface
- Existing sub-classes
- Package name is Java.util.Date
- Milliseconds 1000 milliseconds = 1 seconds
- long time=System. Currenttimemillis ();
- returns a long type because the range of int is exceeded
- Time Origin 0 AD January 1, 1970 Midnight 0:00:00:
- Time and date calculations must depend on the millisecond value
L Construction Method
- Obsolete from jdk1.1 replaced by calendar class
- except date (); Date (long date)
- The date () output is not an object address description overriding the ToString method
Sat Jul 10:58:26 CST 2017 time in current operating system
- Date (long date)
Pass a millisecond value
into a date with 0 points added
- Date Get Set method
GetTime () converts a date to a millisecond value long time=system.currenttimemillis () can also
SetTime () Converts a millisecond value to a date construction method or
L Date Formatting
- DateFormat
- Abstract class for date formatting
- Java.text Bag
- Both abstract and non-abstract methods have
- SimpleDateFormat subclasses can implement abstract methods directly using non-abstract methods
- Create a SimpleDateFormat object
Write date format in construction method
YYYY year
MM Month
Days in DD month
HH 0-23 hrs
Minutes in mm hours
SS sec
New SimpleDateFormat ("A.D. yyyy mm month DD Day m minutes ss seconds");
Chinese characters can be written, but letters must be written as required.
Then call the format () method to return a value that is a string parameter that is a date
L string converted to date object
- Parse method
- Steps
A) Create a SimpleDateFormat object
b) Construction method Specify date format
c) Subclass object Invocation Method Parse pass string returns date
d) The string date in parse must be the same as the specified format
e) Date cannot be entered only select
Calendar
L Concept
- Replaced the date method
- A subclass implementation is required for an abstract class that cannot create an object
- static method static variable year calendar field
- GetInstance () Gets the child class object
L Get Gets the value of the Calendar field
Get (int)
parameter int gets the specific value of which calendar field
Returns an int value
int year=calendar.get (calendar. year);
Year
Months month
Days Date_of_mouth
L Set (int field,int value)
Set Calendar Field specific values
Set (int year,int month,int Day)
The month and day of passing 3 integers
The foreign months are less than the domestic month
L Add (int field, int offset)
The offset of the calendar can specify which one of the fields in the calendar, the offset of the whole number
L GetTime () not used
Convert a Calendar object to a Date object
Practice
L've lived many years.
L Leap Year
- Assign calendar to March 1, add offset Day 29 leap year 28 common year
L Java Calendar
Packaging class overview
- There are eight types of mathematical calculations for the basic type
- Basic types do not need to be expanded for complex operation functions
- The wrapper class solves this problem.
- Any data entered by the user from the interface is stored as a string
- Operations on these strings can only be performed on string operations that cannot be converted to basic type completion operations
- Java provides eight basic types of wrapper classes
A basic type is encapsulated in each class to manipulate more data
Except that int is Iteger char is character the other is the first letter capitalized
- The main learning integer, the other classes and the same as the integer class
- In the Java.lang package
Characteristics
L parseint (String a)
- Switch between a basic data type and a string
- parseint (String a)
- Resolves a string to a signed int integer
- You can only write numbers and no spaces.
L parseint (String s,int Radix)
- Convert other binary numbers to decimal
- The preceding binary number and the back of the system must correspond
- Can write abcdef 16 binary
L Change the base type to a string
- Data type variable + ""
- Integer static Method ToString
- ToString (String s,int radix) to specify the input output up to 36 binary 0-9 A-Z
L Construction Method
- Integer (string s) creates a Interger object that contains a string
- Non-static method Intvalue () returns the int type to convert this string to the base data type
L Other methods
- Three methods and two static member variables
- Max_value base data Type value maximum
- Min_alue basic Data Type value minimum value
- tobinarstring (int) decimal into binary returns string
- tooctalstring (int) decimal to octal
- tohexstring (int) decimal to hexadecimal
Auto-boxing and automatic unpacking
L jdk1.5 After
Data type becomes object auto-boxing
The data in the object changes back to the base data type auto-unpacking
L Automatic Packing
- Integer in=1;
After printing for string 1
For example, collection arraylist<integer> can store 1
- In=in+1
In first In.invalue () to basic type
Then in+1
After in is converted to wrapper class
L Disadvantages
Null pointer exception
If in is null, the compilation is correct, but the operation will be wrong.
L Practice
System class
L Java.lang Bag
L Final Class
L Construction Methods Private outsiders cannot directly create objects
L can access static methods with the class name
L method
- Currenttimemills ()
A) Get current system time
b) can be called once before and after the program is run for statistical program execution time
- Exit ()
A) The virtual machine quits and then stops running the program
b) exit the virtual machine
c) Use the parameter as status code 0 to indicate a normal termination of 1 indicates an abnormal termination
- GC ()
A) recycling of waste
b) such as anonymous objects, etc.
c) override the Finalize () method in the object class to output the statement
- GetProperties ()
GetProperties (String key)
A) Gets the properties of the current operating system
b) Returns a class in the Properties collection similar to ArrayList
c) Output GetProperties () to get all the information
d) file.separator System file location symbols such as Windows \ Unix
Is
- ArrayCopy
A) The principle of variable group Arratlist StringBuffer is used in this
b) The source code is not
c) Copy Replacement
D) is the local method of calling Windows The JVM memory is part of the local method stack and this method runs when it is in the local method stack
Math Class Concepts
• Classes of mathematical calculations
L Tool Class
L square Root logarithmic exponential trigonometric functions
L Java.lang in Bag
L static method
Method
l static int abs (int i)
- Get the absolute value of a parameter
- Math.Abs (int a)
- Floating-point long is available
L static double ceil (double D)
- Returns the smallest integer greater than or equal to D
- Math.cell ()
L static double floor (double D)
- Returns the largest integer less than or equal to D
- Math.floor ()
L Static Double pow (double A, double A,)
- Returns the B-side of a
- Math.pow (2,3) 2 of the 3-time Square
L static double sqrt (double D)
- Returns the square root of a double argument
- If a negative number-2 will output Nan
- Local method
L static double random (double D)
- SOURCE Random Class
- Returns a random number between a 0.0-1.0
- Not recommended for
L Static double round (double D)
- Gets the rounding of the parameters takes an integer
- How to achieve your own + 0.5 strong turn int in the conversion to double
Arrays Tool Class Concept
L contains the contents of an array of operations
L Java.util
L Include sort Lookup
Method
L static void sort (array)
- Sorting arrays in ascending order
- Sorting algorithms are optimized for fast sorting
l static int BinarySearch (array, element found)
- The binary search method of array
- Returns the index of the element that appears in the array
- If the element does not exist return is (-insertion point-1)
A) Ensure that the elements are placed in an orderly manner
b)-index-1
L Static String toString (array)
- Change an array to a string
- and has a certain format
- Principle StringBuilder output array in a format previously written
Practice
L Receive input Storage 10 people's scores
L PUT the last three people into a new array
L Returns a new array
L Program Analysis
- The main method passes over an array
- Sort by using the Sort method
- Create a new array
- Copy the first three elements of a passed array to a new array with arraycopy
- Returns the array
- Main receives this array
- Output with ToString
- You can also use a for loop to traverse the output and remove the first three elements, but it's more troublesome.
BigInteger Concept Introduction
L Long type is the largest integer
L A base type that exceeds a long type cannot be represented
L Become a BigInteger object
L implementation of Big Data operations
L Java.math
Construction method
L can pass byte array integral type has limitations
L Select Pass string to represent an integer of any size
L BigInteger (String s) is an object
Operation
L can carry out arithmetic
- Caller arithmetic
- Calculation results can only be BigInteger objects
l addition Add (another BigInteger object)
- The result is still an object
L subtraction Subtract (another BigInteger object)
The result is still an object
L multiplication Multiply (another BigInteger object)
The result is still an object
L Division Divied (another BigInteger object)
The result is still an object
Bigdeciaml Overview
- 0.09+0.01=0.09999999999999
L infinitely close to 0.1
- Cause the floating-point number is inaccurate in computer-calculated binary
- Super large number floating point arithmetic improves operation Precision
- Java.math
Construction method
L Recommended passing parameters with string
l int and double may go out of the unpredictable
Operation
L Plus minus multiply
- Addition
A) Add
b) Accurate calculation
- Subtraction
A) Subtract
b) Accurate calculation
- Multiplication
c) Multiply
d) Accurate calculation
- Results
0.1 0.68 101.5
L Division Extraction High Precision
- Division Divied
- Results
1.301/100
0.01301
1.301/101
Abnormal infinite Non-circulation
- Workaround: Reload
A) Retention mode
Read the API documentation
. Round_up up one plus 1
. Round_down truncation
. Round_half_up rounding
. Round_half_down Sishe (greater than 0.5 V) into
The Java self-study road-day11