Regular expressions, Pattern and Matcher classes, Math class, Random class. System classes, BigDecimal class

Regular Expressions

  1. Concept: is a kind of man-made rules
  2. Common composition rules

A: character
x character x. Example: 'a' represents the characters A
\ backslash character.
\ n new line (line feed) ( '\ u000A')
\ R & lt carriage return ( '\ u000D')
B: character class
[abc] a, b, or C (Simple)
[^ ABC] any characters except a , b or C (negative)
[a-zA-the z] z to a or a to z, including two letters (range)
character [0-9] comprises 0 to 9.
C: predefined character classes
. any character. My character is itself, how it represents?.
\ D digit: [0-9]
\ w word character: [a-zA-Z_0-9]
things to form words in a regular expression which must have these things make up
D : boundary matcher
at the beginning of the line ^
end of the line $
\ b word boundary
is not a word character place.
Example: Hello World haha; xixi?
E: and Greedy quantifier
X-X-, <=. 1?
X-* X-,> = 0
X-+ X-,> =. 1
X-{n-} X-, n-
X-{n-,} X-, n-
X-{n- , m} X,> = n && <= m

  1. Phone number to determine whether to meet the rules
    11 and can not string beginning with the number 0

String s="[1-9][0-9]{10}";
boolean b = “18791050779”.matches(s);
System.out.println(b);

  1. Check the mailbox
    [email protected] this mailbox for example

String s="[a-zA-Z]\w{5,17}@163\.(com|net|cn|org)";
boolean matches = “[email protected]”.matches(s);
System.out.println(matches);

  1. Regular expressions split function split () method

"912,746,385,021,111 121" and outputs this string collation.

STR = String "27 91 is 46 is 38 is 21 is 50. 11. 1 121";
String [] = ARR str.split ( "+");
System.out.println (of Arrays.toString (ARR)); // get a collection
Arrays .sort (arr);

int [] = INTS new new int [arr.length];
for (int I = 0; I <ints.length; I ++) {
INTS [I] = the Integer.parseInt (ARR [I]); // set the inside all elements are converted to type int number, to obtain the array
}
Arrays.sort (INTS);
the StringBuilder StringBuilder the StringBuilder new new = ();
for (int I = 0; I <ints.length; I ++) {
StringBuilder.Append (INTS [I .]) the append ( "");
}
String trim StringBuilder.ToString = () trim ();. // borrow trim and sort the array to achieve StringBuilder
System.out.println (trim);

Pattern and Matcher classes

  1. A typical call sequence is
    the Pattern of Pattern.compile P = ( "A * B");
    Matcher m = p.matcher ( "aaaaab");
    Boolean m.matches B = ();

  2. da jia ting wo shuo, jin tian yao xia yu, bu shang wan zi xi, gao xing bu? this string of characters printed three letters

String str=“da jia ting wo shuo, jin tian yao xia yu, bu shang wan zi xi, gao xing bu?”;
String regx="\b[a-z]{3}\b";
String[] strings = str.split("[^a-z]+");//除去空字符的字母集合
System.out.println(Arrays.toString(strings));
for (int i = 0; i < strings.length; i++) {
if(strings[i].length()==3){
System.out.println(strings[i]);
}
}

Math class

  1. Math class Overview
    Math class contains methods for performing basic mathematical operations, like ever exponential, logarithmic, trigonometric functions and square root.

  2. Member variable
    public static final double E: natural base-
    public static final double PI: pi

  3. Method members
    public static int abs (int a) the absolute value
    public static double ceil (double a) rounded up
    public static double floor (double a) rounded down
    public static int max (int a, int b) obtaining a maximum value
    public static int min (int a, int b) obtaining the minimum value
    public static double pow (double a, double b) obtaining a b-th power of
    public static double random () Gets a random number with a positive sign double return value greater than or equal to 0.0 and less than 1.0.
    public static int round (float a) rounding
    public static double sqrt (double a) obtaining a positive square root

Random category

  1. Constructors
    public Random () is not given seed, using the default (the current system millisecond value)
    public the Random (long SEED) a long a given type of seed, after every random number generated given the same

  2. Method members
    public int nextInt () // no random number range parameter represents the range of type int
    public int nextInt (int n) // can specify a range of random numbers
    void nextBytes (byte [] bytes) generates a random bytes and placed in an empty byte array provided by the user.

System class

  1. System Overview class
    System class contains several useful class fields and methods. It can not be instantiated.

  2. Member method
    public static void gc () // call the garbage collector
    public static void exit (int status) // quit java virtual machine 0 0 non-normal exit as a leave
    public static long currentTimeMillis () // get the current time in milliseconds value

BigDecimal class

  1. Accuracy can meet your requirements, that is, high precision

  2. Constructor
    public BigDecimal (String val)

  3. Method members
    public BigDecimal add (BigDecimal augend) // add
    public BigDecimal subtract (BigDecimal subtrahend) // Save
    public BigDecimal multiply (BigDecimal multiplicand) // by
    public BigDecimal divide (BigDecimal divisor) // division
    public BigDecimal divide (BigDecimal divisor, int scale, int roundingMode) // scale behind the decimal point several
    // roundingMode trade-offs such as rounding mode

Published 43 original articles · won praise 7 · views 1778

Guess you like

Origin blog.csdn.net/y18791050779/article/details/102933607