Java regularity, time conversion, converting object array to character array, enumeration constructor, BigDecimal conversion

Java regular expression

Please refer to the tutorial: http://c.biancheng.net/view/5812.html

public static void main(String[] args) {
    
    
   String regex = "^\\w+[@].*\\.((com)|(cn))(\\.com|\\.cn)?";
   String b = "[email protected]";
   //还可以使用Pattern和Matcher,他们有很多方法,可参考https://www.runoob.com/java/java-tutorial.html
   //Pattern p = Pattern.compile(regex);
   //Matcher m = p.matcher(b);
   //System.out.println(m.matches());
   System.out.println(b.matches(regex));
  }

Why Java regex requires two slashes

Online regular expression-regex100.com

Java: LocalDate, LocalDateTime, Date and timestamp conversion

LocalDate, LocalDateTime, Date and timestamp conversion
localDateTime gets the time specified date format

Convert object array to character array in java

Object[] obj= {
    
    "a","b","c"};
String[] stringArray = Arrays.stream(obj).toArray(String[]::new);
String[] stringArray = Arrays.copyOf(obj, obj.length, String[].class);
String[] stringArray = Arrays.asList(obj).toArray(new String[obj.length]);

→Reference

java enumeration constructor

The number of calls to the java enumeration constructor. The number of
calls to the java enumeration constructor. Reference 2
Reference 3

//自定义构造器的枚举
public enum Role {
    
    
    ROLE_PERSONAL("personal","个人"),
    ROLE_MANAGER("manager","单位"),
    ROLE_DIVISION("division","主管"),
    ROLE_UNDEFINED,//可以有参无参混合用,但是这种混合需要手动声明无参构造
    ;
    private String roleCode;
    private String roleName;

    Role() {
    
    }

    Role(String roleCode, String roleName) {
    
    
        this.roleCode = roleCode;
        this.roleName = roleName;
    }

    public String getRoleCode() {
    
    
        return roleCode;
    }

    public void setRoleCode(String roleCode) {
    
    
        this.roleCode = roleCode;
    }

    public String getRoleName() {
    
    
        return roleName;
    }

    public void setRoleName(String roleName) {
    
    
        this.roleName = roleName;
    }
}

type conversion

BigDecimal and long conversion

Guess you like

Origin blog.csdn.net/qq_45699990/article/details/120646538