一.Math System Runtime1.Math了解2.System了解2.应用想知道蓝色代码运行的时间可以在前后分别调用这个方法 两个时间相减得到时间差3.RuntimeRuntime源码单例6.初始运行时会标红 只需按Alt回车直接使用名称前提是先把这个软件配置到环境变量二.*BigDecimal--解决精度失真egab是double类型 但a1b1都是String类型谁调用 valueOf就把括号里的内容转成谁的类型valueOf和new bigdecimal1.BigDecimal.valueOf(xxx)静态方法内部会自动优化会用缓存不会有精度坑你传 double 它也尽量帮你转干净推荐日常使用BigDecimal bd BigDecimal.valueOf(0.1);2.new BigDecimal(xxx)构造方法完完全全如实创建不缓存、不优化传 double 会直接炸精度只有传字符串时才安全// 危险精度丢失 BigDecimal bad new BigDecimal(0.1); // 安全必须用字符串 BigDecimal good new BigDecimal(0.1);3.想安全、想省事 → 用 valueOf要绝对精确、要字符串 → 用 new BigDecimal (xxx)永远不要 new BigDecimal (0.1)但有的时候会无法运算无限循环、不循环小数可以用到方法6RoundingMode.HALF-UP代表四舍五入2表示小数部分保留2位RoundingMode.HALF-UP表示四舍五入BigDecimal只是用来解决精度问题的手段最后转成double才是目的------------------注意事项三.传统时间 日期了解1.Date1创建一个Date对象 拿到当前时间2拿到时间毫秒值3把时间毫秒值又转成日期对象两秒之后的时间是多少4直接把日期对象的时间通过setTime方法进行修改2.SimpleDateFormat1场景12场景2练习秒杀活动3.Calendar抽象类tip要得到哪个信息可以在1.的运行结果里面找对应的这个方法返回的是Calendar的子类的实例(月份是从0开始四.***新增时间日期1.LocalDate LocalTime LocalDateTime1LocalDate(好处当前时间不会丢失2LocalTime3LocalDateTime前六个都是LocalDate和LocalTime的综合2.ZoneId ZoneDateTime1ZoneId查找想要时区的写法CtrlF键2ZoneDateTime其中 选择世界标准时间并且 这里的now也可以像Localxx一样调用相应的方法eg。3.Instant......instant适合用来做记录localdatatime适合拿时间4.DateTimeFormatter2.是正向格式化 3.是反向格式化DateTimeFormatter.ofPattern(yyyy-MM-dd HH:mm:ss)创建一个自定义的日期时间格式化器按照指定的模式字符串yyyy-MM-dd HH:mm:ss来解析 / 格式化日期时间字符串。LocalDateTime.parse(stringDate, dateTimeFormatter)将符合指定格式的字符串解析为LocalDateTime对象。“统一输入格式”是结合ofPattern定义统一格式 parse 方法共同完成的第一步定义规则ofPattern定义唯一的合法格式比如yyyy-MM-dd HH:mm:ss第二步校验 转换parse方法用这个规则去校验输入的字符串如果输入符合规则如2026-03-23 15:30:00→ 解析成LocalDateTime对象如果输入不符合规则如2026/03/23 15:30→ 直接抛出DateTimeParseException异常。5.Period Duration1Period2Duration五.Arrays1.数据数组(注意包前不包后用到匿名内部类源码及运行过程以4的数据为例2.对象数组--自定义排序1方法112或者直接简化成降序实现3----2方法2匿名内部类注意此时约定返回类型是int类型 强转可能会有风险 所以完整代码或者简写为compare源码--返回类型为int降序代码六.Lambda表达式1.认识Lambda表达式Lambda表达式只能简化函数式接口的匿名内部类Lambda 只能用于函数式接口匿名内部类可用于接口、普通类、抽象类Lambda 代码更简洁Lambda 效率更高不是简单生成类可以有默认方法可以有静态方法可以有Object 里的 public 方法只要抽象方法只有一个就是函数式接口。FunctionalInterface public interface MyInterface { void run(); // 只有这一个抽象方法 }四大内置函数式接口SupplierT 生产者T get()无参返回一个数据无中生有ConsumerT 消费者void accept(T t)接收数据不返回只进不出FunctionT,R 函数 / 转换R apply(T t)接收 T返回 R进去变出来PredicateT 断言 / 判断boolean test(T t)接收 T返回 boolean判断对错下面哪些是函数式接口RunnableComparatorConsumerListMap答案Runnablerun()、Comparatorcompare(T o1, T o2)、Consumeraccept(T t) 是。Listadd、remove、get、size、isEmpty……、Map put、get、remove、size……不是。2.Lambda表达式的省略规则无参 →()一参 → 直接写变量多参 →(a,b)有返回值一条语句 → 直接写表达式不用return1无返回值 无参数FunctionalInterface interface NoParameterNoReturn { void test(); }LambdaNoParameterNoReturn a () - {};2无返回值 一个参数FunctionalInterface interface OneParameterNoReturn { void test(int a); }LambdaOneParameterNoReturn b a - {};3无返回值 多个参数FunctionalInterface interface MoreParameterNoReturn { void test(int a, int b); }LambdaMoreParameterNoReturn c (a, b) - {};4有返回值 无参数FunctionalInterface interface NoParameterReturn { int test(); }LambdaNoParameterReturn d () - 10;5有返回值 一个参数FunctionalInterface interface OneParameterReturn { int test(int a); }LambdaOneParameterReturn e a - a * 2;6有返回值 多个参数FunctionalInterface interface MoreParameterReturn { int test(int a, int b); }LambdaMoreParameterReturn f (a, b) - a b;3.变量捕获内部类 / Lambda 里面用到了外面的变量就叫捕获变量。int a 100; // 外部变量 new Test(){ public void func() { System.out.println(a); // 这里用到了 a → 捕获 a } };规则被捕获的变量要么是 final要么是 没改过值的变量effectively final。int a 100; new Test(){ public void func() { a 99; // ❌ 编译报错 } };虽然没写 final但从头到尾没改过值就是 effectively final。int a 100; // 没写 final但没改过 → 等效 final ✅final int a 100; // 写了 final → ✅int a 100; a 99; // 改过了 → ❌ 不是等效 final内部类访问外部变量有什么要求外部变量必须是final或者effectively final不能被修改否则编译报错。4.Lambda在集合中的使用方法引用-类名方法1Collection接口import java.util.ArrayList; import java.util.function.Consumer; public class TestForEach { public static void main(String[] args) { // 1. 创建集合并添加数据 ArrayListString list new ArrayList(); list.add(Hello); list.add(bit); list.add(hello); list.add(lambda); // // 写法1匿名内部类原始 // System.out.println( 匿名内部类 ); list.forEach(new ConsumerString() { Override public void accept(String str) { System.out.print(str ); } }); System.out.println(); // // 写法2Lambda 表达式推荐 // System.out.println( Lambda ); list.forEach(s - System.out.print(s )); System.out.println(); // // 写法3方法引用最简洁 // System.out.println( 方法引用 ); list.forEach(System.out::print); } }2List接口import java.util.ArrayList; import java.util.Comparator; public class TestSort { public static void main(String[] args) { ArrayListString list new ArrayList(); list.add(Hello); list.add(bit); list.add(hello); list.add(lambda); // 匿名内部类按字符串长度排序 list.sort(new ComparatorString() { Override public int compare(String str1, String str2) { // 比较长度升序 return str1.length() - str2.length(); } }); // Lambda按长度排序 list.sort((str1, str2) - str1.length() - str2.length()); // 方法引用写法 :: list.sort(Comparator.comparingInt(String::length));//(字符串::取长度) System.out.println(list); } }3Map接口import java.util.HashMap; import java.util.function.BiConsumer; public class TestMapForEach { public static void main(String[] args) { HashMapInteger, String map new HashMap(); map.put(1, hello); map.put(2, bit); map.put(3, hello); map.put(4, lambda); //匿名内部类 map.forEach(new BiConsumerInteger, String() { Override public void accept(Integer k, String v) { System.out.println(k v); } }); //Lambda map.forEach((k, v) - System.out.println(k v)); //方法引用 map.forEach(TestMapMethodRef::print); } //自己定义方法引用的print public static void print(Integer k, String v) { System.out.println(k v); } }5.优缺点Lambda 表达式优点代码极其简洁省去大量匿名内部类模板代码支持函数式编程方便结合 Stream 处理集合易于做并行计算充分利用多核 CPU大大简化集合操作遍历、排序、过滤等Lambda 表达式缺点可读性变差复杂逻辑不如普通代码清晰调试困难出错时不容易定位问题单线程场景下性能不一定比传统 for 循环高七.方法引用进一步简化Lambda表达式1. 静态方法引用类名::静态方法名// Lambda () - Integer.parseInt(123); // 方法引用 Integer::parseInt;2. 实例方法引用对象方法对象名::普通方法名String str hello; // Lambda () - str.length(); // 方法引用 str::length;3. 任意对象的实例方法类方法类名::普通方法名// Lambda (String s) - s.length(); // 方法引用 String::length;4. 构造方法引用类名::new// Lambda () - new String(); // 方法引用 String::new;5. 数组构造引用数组类型[]::new// Lambda len - new int[len]; // 方法引用 int[]::new;6. 父类方法引用super::方法名最常用的 4 个静态方法类名::方法对象方法对象::方法任意对象方法类名::方法构造方法类名::new