标题.append("matches匹配").append("group()").append("数据的加密解密")
对象克隆:clone();
深克隆和浅克隆的区别:是否可隆对象中其他引用结构里对应的数据.
浅克隆:
深克隆:
实现四舍五入:round(num,精确几位);
通过pow(num,平方数),再调用round()实现精准四舍五入方法重写
Date类:
常用方法:
实现代码:
Calender类:
getInstance();
getInstance的使用:
* 在主函数开始时调用,返回一个实例化对象,此对象是static的,在内存中保留着它的引用,即内存中有一块区域专门用来存放静态方法和变量,
* 可以直接使用,调用多次返回同一个对象。
getInstance 和 new的区别;
大部分类都可以用new,new就是通过生产一个新的实例对象,或者在栈上声明一个对象,每部分的调用
*都是用的一个新的对象
getInstance在单例模式(保证一个类仅有一个实例,并提供一个访问它的全局访问点)的类中常见,用来生成唯一的实例,getInstance往往是static的。
Java中instance的用法_阿特密斯X的博客-CSDN博客_instance
format();
Java中String.format()的简单用法介绍
在运用字符串的时候,我们常常会用到String.fromat()函数来对字符串进行加工,得到我们想要的格式,那我们就来看看一些简单用法。
String.format()函数相当于将括号内的量,按照自己的想要的格式拼接成一个字符串,然后输出。作用效果有点像C语言中的printf()函数。
常用转换符:
SimpleDateFormat(yyyy-MM-dd-HH-mm-ss-SSS) ,日期时间格式化模式
LocalDate类实现多线程字符串转日期操作(用SimpleDate实现多线程字符串转日期会有同步问题,但是日期转字符串没有),下面实现代码:
public class demo325 {
public static void main(String[] args) throws Exception{
DateTimeFormatter formatter=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
ZoneId zoneId= ZoneId.systemDefault();
for(int x=0;x<10;x++){
new Thread(()->{
LocalDateTime localDateTime=LocalDateTime.parse("2002-12-12 21:22:44",formatter);
Instant instant=localDateTime.atZone(zoneId).toInstant();
Date date=Date.from(instant);
System.out.println(Thread.currentThread().getName()+date);
},"sad").start();
}
}
}
正则表达式:
实现代码:
matches匹配
public class demo325{
public static void main(String[] args) {
String str="safjgi240-*(&(*&^&%";
String regex="[^a-z]";
System.out.println(str.replaceAll(regex,""));
}
}
正则表达式邮箱匹配:
电话号码匹配:
group();
在java中使用正则表达式返回符合正则表达式的字符串就要用到group(),group中记录了所有符合指定表达式的字符串
数据加密解密操作
@functional interface
@FunctionalInterface的作用和观点纠正:接口其实是继承于Object的。_遗念火的博客-CSDN博客_functional interface 作用
Threadlocal类
通过ThreadLocal类实现多线程的储物柜:
class Message{
private String content;
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
class MessagePrint{
public static void print( ){
System.out.println(Resourse.MESSAGES.get().getContent());
}
}
class Resourse{
public static final ThreadLocal<Message> MESSAGES=new ThreadLocal<>();
}
public class demo325{
public static void main(String[] args) {
String[] value = new String[]{"hxw", "" + "csj", "liumin"};
for (String msg : value) {
new Thread(() -> {
Resourse.MESSAGES.set(new Message());
Resourse.MESSAGES.get().setContent(msg);
MessagePrint.print();
}).start();
}
}
}
定时调度