Java normal expressions and their use of common classes math, Calendar, Date, BigDecimal, Biginterger, System, Rondom

Source: Internet
Author: User
Tags character classes dateformat square root time in milliseconds

1: Regular Expressions (understanding)
(1) A string that conforms to a certain rule
(2) Common rules
A: Character
x character X. Example: ' A ' denotes character a
\ \ backslash character.
\ n New Line (newline) character (' \u000a ')
\ r return character (' \u000d ')

B: Character class
[ABC] A, B or C (simple Class)
[^ABC] Any character except A, B, or C (negation)
[A-za-z] A to Z or A to Z, the letters at both ends are included (range)
[0-9] 0 to 9 characters are included

C: Predefined character classes
. Any character. And mine is. The character itself, how to express it? \.
\d number: [0-9]
\w Word character: [a-za-z_0-9]
Things that make up words in regular expressions must have these things.

D: Boundary Matching device
^ The beginning of the line
End of the $ line
\b Word boundaries
is the place where the word character is not.
Example: Hello World?haha;xixi

E:greedy number of words
X? X, not once or once
X* X, 0 or more times
x+ X, one or more times
X{n} X, exactly n times
X{n,} X, at least n times
X{n,m} X, at least n times, but no more than m times
(3) Common function: (who is it used separately?)
A: Judging function
Public boolean matches of the String class (string regex)
B: Split function
Public string[of the String class] split (string regex)
C: Replace function
public string ReplaceAll of the String class (String regex,string replacement)
D: Get Features
Pattern and Matcher
Pattern p = pattern.compile ("A*b");
Matcher m = P.matcher ("Aaaaab");

Find (): Lookup does not exist
Group (): Get the data you just looked up
Note: Group must first call find after.
(4) Case
A: Determine phone number and mailbox
B: Split data according to different rules
C: Replace the number in the forum with *
D: Get a 3-character word in a string

2:math (Master)
(1) classes that operate on mathematical operations
(2) Common methods (self-completion)
A: Absolute value: public static int abs (int a) returns the absolute value of an int.
B: Rounding up: public static double Ceil (double A) returns the smallest (nearest negative infinity) Double value, which is greater than or equal to the parameter and equals an integer.
C: Rounding down: public static double Floor (double a) returns the largest (closest to positive infinity) Double value, which is less than or equal to the parameter and equals an integer.
D: Large value in two data: public static int max (int a,int b) returns the larger of the two int values.
Power of E:a B: public static double pow (double a,double b) Returns the value of the second parameter power of the first argument.
F: Random number: public static double Random () returns a double with a positive value greater than or equal to 0.0 and less than 1.0
G: Round: public static int round (float a) returns an int that is closest to the parameter.
H: Positive square root: public static double sqrt (double A) returns the positive square root of a double value that is correctly rounded
(3) Case:
A: Guess the number games
B: Get random numbers of any range

3:random (understanding)
(1) A class for generating random numbers
(2) Construction method:
A:random () default seed, different random number generated each time
B:random (long Seed) specifies the seed, and the random number is the same each time the seed is the same
(3) member method:
A:int Nextint () returns the random number in the INT range
B:int nextint (int n) returns the random number in the range of [0,n]

4:system (Master)
(1) System classes, which provide some useful fields and methods
(2) member method (self-completion)
A: Run the garbage collector: public static void GC () runs the garbage collector.
B: Exit jvm:public static void exit (int status) to terminate the currently running Java virtual machine.
C: Gets the millisecond value of the current time: public static long Currenttimemillis () returns the current time in milliseconds.
D: Array copy: public static void Arraycopy (Object src,int srcpos,object dest,int destpos,int length) copies an array from the specified source array, starting at the specified position, Ends at the specified position in the destination array.

5:biginteger (Understanding)
(1) operation for large integers
(2) constructor
A:biginteger (String s)
(3) member method (self-filled)
A: Add: Public BigInteger Add (BigInteger val) returns BigInteger
B: minus: Public BigInteger subtract (BigInteger val) whose value is (this + val) returns (Thi S-val) of the BigInteger.
C: Multiply: Public BigInteger multiply (BigInteger val) returns the BigInteger whose value is (this * val).
D: Except: Public BigInteger Divide (BigInteger val) returns the BigInteger whose value is (This/val).
E: Quotient and remainder: public biginteger[] Divideandremainder (BigInteger val) returns an array of two BigInteger containing (this/val) followed (this% val).

6:bigdecimal (Understanding)
(1) floating-point data is an operation that loses precision. Therefore, it is recommended to use BigDecimal for floating-point data operations. (Financial-related projects)
(2) constructor method
A:bigdecimal (String s)
(3) member method:
A: Add: Public BigDecimal Add (BigDecimal augend) returns a BigDecimal, The value is (this + augend), which is the scale of Max (This.scale (), Augend.scale ()).
B: minus: Public BigDecimal subtract (BigDecimal subtrahend) returns a BigDecimal with a value of (this-subtrahend) with a scale of Max (This.scale () , Subtrahend.scale ()).
C: Multiply: Public BigDecimal multiply (BigDecimal multiplicand) returns a BigDecimal with a value of (Thisxmultiplicand) with a scale of (This.scale ( ) + Multiplicand.scale ()).
D: Except: Public BigDecimal divide (BigDecimal divisor) returns a BigDecimal with a value of (this/divisor) with a preferred scale of (This.scale ()- Divisor.scale ()); If the exact quotient value cannot be represented (because it has an infinite decimal extension), the ArithmeticException is thrown.
E: Keep decimals several: public BigDecimal divide (BigDecimal divisor,
int roundingmode) returns a BigDecimal with a value of (this/divisor), Its scale is This.scale (). If rounding must be performed to produce a result with the given scale, the specified rounding mode is applied.

7:date/dateformat (Master)
(1) Date is a class of dates that can be accurate to milliseconds.
A: Construction method
Date ()
Date (long time)
B: Member Method
GetTime ()
SetTime (long time)
C: Conversion of date and millisecond values to each other
Case: How many days have you been in this world?
(2) DateFormat classes that are formatted for dates and parsed for strings, but are abstract classes, use their subclasses SimpleDateFormat
A:simpledateformat (String pattern) given pattern
YYYY-MM-DD HH:mm:ss
B: Conversion of dates and strings
A:date--String
Format ()

B:string--Date
Parse ()
C: Case:
A tool class for date manipulation was created.

8:calendar (Master)
(1) The Calendar class, which encapsulates all the Calendar field values, can be obtained using a uniform method based on the incoming different calendar fields.
(2) How do I get a calendar object?
Calendar RightNow = Calendar.getinstance ();
Essentially, the subclass object is returned.
(3) member method
A: Get the corresponding value according to the Calendar field
public int get (int field) returns the value of the given Calendar field.
B: Determine whether to add or subtract the value of the corresponding Calendar field based on the Calendar field and a positive negative number
public void Set (int field,int value) sets the given Calendar field to the given value. Regardless of the relaxed mode, this value is not interpreted by this method.
C: Set Calendar object's Month day
Public final void Set (int year,int month,int date) Sets the value of the Calendar field year, month, and Day_of_month.
(4) Case:
Calculate how many days in February of any year?

Java normal expressions and their use of common classes math, Calendar, Date, BigDecimal, Biginterger, System, Rondom

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.