xerga 1 年間 前
コミット
6ebc030fd0

+ 11 - 0
JavaSE/day13/day13.iml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 30 - 0
JavaSE/day13/src/com/lc/day13/date03/TestDate.java

@@ -0,0 +1,30 @@
+package com.lc.day13.date03;
+
+import java.util.Date;
+
+/**
+ * ClassName: TestDate
+ *
+ * @Author 爱扣钉-陈晨
+ * @Create 2024/1/9 13:41
+ * @Version 1.0
+ */
+public class TestDate {
+
+    public static void main(String[] args) {
+        //Date
+        Date date = new Date();
+
+        System.out.println(date);
+
+        //Date(long date)
+        Date date1 = new Date(1000*60*60*24); // 1970-01-01 08:00:00
+        System.out.println(date1);
+
+
+        //获取毫秒值 从1970开始
+        long time = date1.getTime();
+        System.out.println(time);
+    }
+
+}

+ 35 - 0
JavaSE/day13/src/com/lc/day13/date04/Test01.java

@@ -0,0 +1,35 @@
+package com.lc.day13.date04;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * ClassName: Test01
+ *
+ * @Author 爱扣钉-陈晨
+ * @Create 2024/1/9 13:50
+ * @Version 1.0
+ */
+public class Test01 {
+
+    public static void main(String[] args) throws ParseException {
+        //字符串  - 时间
+        String s1 =  "2023-01-01 12:00:00";
+
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+        //解析为时间
+        Date parse = sdf.parse(s1);
+
+        System.out.println(parse);
+
+        // 时间  字符串
+        Date date = new Date();
+
+        String format = sdf.format(date);
+
+        System.out.println(format);
+
+    }
+}

+ 58 - 0
JavaSE/day13/src/com/lc/day13/date04/Test02.java

@@ -0,0 +1,58 @@
+package com.lc.day13.date04;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * ClassName: Test01
+ *
+ * @Author 爱扣钉-陈晨
+ * @Create 2024/1/9 13:50
+ * @Version 1.0
+ */
+public class Test02 {
+
+    public static void main(String[] args) throws ParseException {
+        //当前时间 以及一个月之后的时间
+        Calendar ins = Calendar.getInstance();
+
+        //add 加减
+        ins.add(Calendar.MONTH,1);
+        ins.add(Calendar.MONTH,-1);
+
+        //+1
+        ins.add(Calendar.YEAR,1);
+
+        //获取年份 get
+        int y1 = ins.get(Calendar.YEAR);
+        int y2 = ins.get(1);
+
+        System.out.println(y1);
+        System.out.println(y2);
+
+        //月份
+        int m = ins.get(Calendar.MONTH);
+        System.out.println(m); // 0 +
+
+        //日期
+        int d = ins.get(Calendar.DAY_OF_MONTH);
+        System.out.println(d);
+
+        System.out.println(y1+"年"+(m+1)+"月"+d+"日");
+
+
+
+        //设置生日
+        Calendar bir = Calendar.getInstance();
+
+        bir.set(Calendar.YEAR,1999);
+        bir.set(Calendar.MONTH,0);
+        bir.set(Calendar.DAY_OF_MONTH,1);
+
+        //时间
+        Date time = bir.getTime();
+        System.out.println(time);
+    }
+}

+ 54 - 0
JavaSE/day13/src/com/lc/day13/date05/Test01.java

@@ -0,0 +1,54 @@
+package com.lc.day13.date05;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.Month;
+
+/**
+ * ClassName: Test01
+ *
+ * @Author 爱扣钉-陈晨
+ * @Create 2024/1/9 15:16
+ * @Version 1.0
+ */
+public class Test01 {
+
+    public static void main(String[] args) {
+        // LocalDate  日期
+        LocalDate localDate = LocalDate.now();
+        System.out.println(localDate);
+        
+        // of
+        LocalDate localDate1 = LocalDate.of(2023, 12, 31);
+        System.out.println(localDate1);
+
+        // LocalTime  时间
+        LocalTime localTime = LocalTime.now();
+        System.out.println(localTime);
+
+
+        // LocalDateTime  日期时间
+        LocalDateTime localDateTime = LocalDateTime.now();
+        System.out.println(localDateTime);
+
+        int year = localDateTime.getYear();
+        int month = localDateTime.getMonthValue();
+        int dayOfMonth = localDateTime.getDayOfMonth();
+        System.out.println(year+"-"+month+"-"+dayOfMonth);
+
+        //设置
+        LocalDateTime localDateTime1 = localDateTime.withYear(2022).withMonth(12).withDayOfMonth(31);
+
+        System.out.println(localDateTime1);
+
+        //减
+        LocalDateTime localDateTime2 = localDateTime.minusYears(1);
+        System.out.println(localDateTime2);
+
+        //加
+        LocalDateTime localDateTime3 = localDateTime.plusYears(10);
+        System.out.println(localDateTime3);
+
+    }
+}

+ 41 - 0
JavaSE/day13/src/com/lc/day13/date05/Test02.java

@@ -0,0 +1,41 @@
+package com.lc.day13.date05;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.TemporalAccessor;
+
+/**
+ * ClassName: Test01
+ *
+ * @Author 爱扣钉-陈晨
+ * @Create 2024/1/9 15:16
+ * @Version 1.0
+ */
+public class Test02 {
+
+    public static void main(String[] args) {
+        //时间转换
+        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+
+        //当前时间
+        LocalDateTime now = LocalDateTime.now();
+
+        //转换 字符串
+        String format = dtf.format(now);
+
+        System.out.println(format);
+
+        //字符串 format
+        TemporalAccessor parse = dtf.parse(format);
+        // 时间
+        LocalDateTime from = LocalDateTime.from(parse);
+
+        System.out.println(from);
+
+        //LocalDateTime 时间类提供的
+        LocalDateTime parse1 = LocalDateTime.parse(format, dtf);
+        System.out.println(parse1);
+    }
+}

+ 23 - 0
JavaSE/day13/src/com/lc/day13/integer06/TestInteger.java

@@ -0,0 +1,23 @@
+package com.lc.day13.integer06;
+
+/**
+ * ClassName: TestInteger
+ *
+ * @Author 爱扣钉-陈晨
+ * @Create 2024/1/9 16:14
+ * @Version 1.0
+ */
+public class TestInteger {
+
+    public static void main(String[] args) {
+
+        Integer i1 = 100;
+
+        int i2 = 100;
+
+
+
+
+
+    }
+}

+ 29 - 0
JavaSE/day13/src/com/lc/day13/integer06/TestInteger1.java

@@ -0,0 +1,29 @@
+package com.lc.day13.integer06;
+
+/**
+ * ClassName: TestInteger
+ *
+ * @Author 爱扣钉-陈晨
+ * @Create 2024/1/9 16:14
+ * @Version 1.0
+ */
+public class TestInteger1 {
+
+    public static void main(String[] args) {
+        //构造
+        //Integer i1 = new Integer(1);
+        //Integer s = new Integer("123");
+
+        Integer i1 = 1000;
+
+        int i = i1.compareTo(1001);
+        System.out.println(i);
+
+        //比较
+        int compare = Integer.compare(10, 20);
+        System.out.println(compare);
+
+        //
+
+    }
+}

+ 31 - 0
JavaSE/day13/src/com/lc/day13/integer06/TestInteger2.java

@@ -0,0 +1,31 @@
+package com.lc.day13.integer06;
+
+/**
+ * ClassName: TestInteger
+ *
+ * @Author 爱扣钉-陈晨
+ * @Create 2024/1/9 16:14
+ * @Version 1.0
+ */
+public class TestInteger2 {
+
+    public static void main(String[] args) {
+        //int
+        int a =10;
+        //integer
+        Integer b = 20;
+
+        int c = b;
+
+        Integer d = a;
+
+        //自动装箱
+        Integer e = 20;
+        //自动拆箱
+        int i = e + 10;
+
+        //自动装箱
+        Integer i1 = e + 30;
+
+    }
+}

+ 51 - 0
JavaSE/day13/src/com/lc/day13/integer06/TestInteger3.java

@@ -0,0 +1,51 @@
+package com.lc.day13.integer06;
+
+/**
+ * ClassName: TestInteger
+ *
+ * @Author 爱扣钉-陈晨
+ * @Create 2024/1/9 16:14
+ * @Version 1.0
+ */
+public class TestInteger3 {
+
+    public static void main(String[] args) {
+        //基本  包装类  字符串
+
+        //基本  包装类
+        int a = 10;
+        Integer b = a;  //方式1
+        Integer i = Integer.valueOf(a); //方式2
+
+        //包装类  基本
+        Integer c = 10;
+
+        int d = c; //方式1
+        int i1 = c.intValue(); //方式2
+
+        //基本  字符串
+        int e = 10;
+        String str = e + ""; //方式1
+        String str1 = String.valueOf(e); //方式2
+
+        //字符串 基本
+        String f = "10";
+        int j = Integer.parseInt(f); //方式1
+        //double v = Double.parseDouble("10");
+        //int j1 = new Integer(f); //方式2
+
+
+        //字符串 包装类
+        String g = "10";
+        Integer k = Integer.valueOf(g);
+
+
+        //包装类 字符串
+        Integer l = 10;
+
+        String string = l.toString();
+        String s = l + ""; //拆箱
+        String s1 = String.valueOf(l);//装箱
+
+    }
+}

+ 50 - 0
JavaSE/day13/src/com/lc/day13/integer06/TestInteger4.java

@@ -0,0 +1,50 @@
+package com.lc.day13.integer06;
+
+/**
+ * ClassName: TestInteger
+ *
+ * @Author 爱扣钉-陈晨
+ * @Create 2024/1/9 16:14
+ * @Version 1.0
+ */
+public class TestInteger4 {
+
+    public static void main(String[] args) {
+       //Integer a = 10;
+
+       //private final int value;
+
+//        Integer a = 1;
+//        Integer b = 1;
+//        System.out.println(a == b);// T
+//
+//        Integer i = 128; //Integer i = new Integer(128);
+//        Integer j = 128;
+//        System.out.println(i == j);// F
+//
+//        Integer m = new Integer(1);
+//        Integer n = 1;
+//        System.out.println(m == n);// F
+//
+//        Integer x = new Integer(1);
+//        Integer y = new Integer(1);
+//        System.out.println(x == y);// F
+
+//        Double d1 = 1.0;
+//        Double d2 = 1.0;
+//        System.out.println(d1==d2);// F
+
+//        Integer i = 1000;
+//        double j = 1000;
+//        System.out.println(i==j); // 拆箱
+
+//        Integer i = 1000;
+//        int j = 1000;
+//        System.out.println(i==j);
+//
+//        Integer i = 1;
+//        Double d = 1.0;
+//        System.out.println(i==d);
+
+    }
+}

+ 48 - 0
JavaSE/day13/src/com/lc/day13/str01/TestString.java

@@ -0,0 +1,48 @@
+package com.lc.day13.str01;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+
+/**
+ * ClassName: String
+ *
+ * @Author 爱扣钉-陈晨
+ * @Create 2024/1/9 9:22
+ * @Version 1.0
+ */
+public class TestString {
+
+    public static void main(String[] args) throws UnsupportedEncodingException {
+        //构造
+        String s = new String("123"); //创建两个值
+
+        String s1 = new String();
+
+        //编码
+        byte[] bytes = {-28, -72, -83, -27, -101, -67}; // 中国 utf-8
+
+        //解码
+        String s2 = new String(bytes , "utf-8");
+
+        //字节
+        System.out.println(s2);
+
+        //编码
+        byte[] bytes1 = "中国".getBytes("GBK");
+        //[-42, -48, -71, -6]
+        System.out.println(Arrays.toString(bytes1));
+
+        //汉字
+        // gbk 编码 一个汉字占2个字节
+        // utf-8 编码 一个汉字占3个字节
+
+        //文件 java
+
+        char[] chars = {'中','国'};
+        String s3 = new String(chars);
+
+        System.out.println(s3);
+
+        String s4 = "中国";
+    }
+}

+ 39 - 0
JavaSE/day13/src/com/lc/day13/str01/TestString01.java

@@ -0,0 +1,39 @@
+package com.lc.day13.str01;
+
+import java.util.Arrays;
+
+/**
+ * ClassName: TestString01
+ *
+ * @Author 爱扣钉-陈晨
+ * @Create 2024/1/9 9:33
+ * @Version 1.0
+ */
+public class TestString01 {
+    /*
+     **字符串 -->  字符数组:**
+    - public char[] toCharArray():将字符串中的全部字符存放在一个字符数组中的方法。
+    - public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin):提供了将指定索引范围内的字符串存放到数组中的方法。
+    **字符串 --> 字节数组:(编码)**
+    - public byte[] getBytes() :使用默认字符集将 String 转为 byte 序列,结果存储到一个新的 byte 数组中。
+    - public byte[] getBytes(String charsetName) :使用指定字符集。
+     **字节数组 --> 字符串:(解码)**
+    - String(byte[]):通过默认字符集解码 byte 数组,返回 String。
+    - String(byte[],int offset,int length) :用字节数组的一部分,起始位置和长度返回String
+    - String(byte[], String charsetName ) 按照指定的字符,解码byte字节数组。
+     */
+    public static void main(String[] args) {
+        String s1 = "helloworld";
+        //将字符串中的全部字符存放在一个字符数组中
+        char[] charArray = s1.toCharArray();
+        System.out.println(Arrays.toString(charArray));
+
+        //String s = new String(charArray , 0 ,10);
+        char[] arr = new char[2];
+        s1.getChars(0,2,arr, 0);
+
+        System.out.println(arr);
+    }
+
+
+}

+ 40 - 0
JavaSE/day13/src/com/lc/day13/str01/TestString02.java

@@ -0,0 +1,40 @@
+package com.lc.day13.str01;
+
+import java.util.Arrays;
+
+/**
+ * ClassName: TestString01
+ *
+ * @Author 爱扣钉-陈晨
+ * @Create 2024/1/9 9:33
+ * @Version 1.0
+ */
+public class TestString02 {
+
+    public static void main(String[] args) {
+        //boolean isEmpty():字符串是否为空
+        String str = "  ";
+        //空格处理
+        System.out.println(str.isEmpty());
+
+        //trim
+        String trim = str.trim();
+        System.out.println(trim);
+
+        //isBlank
+        //boolean isBlank():字符串是否为空或仅包含空格
+        boolean blank = str.isBlank();
+        System.out.println(blank);
+
+        //equalsIgnoreCase
+
+        String s1 = "abc";
+        String s2 = "Abc";
+        System.out.println(s1.equalsIgnoreCase(s2));
+
+        //验证码  大小写  ABCD  abcd
+
+    }
+
+
+}

+ 30 - 0
JavaSE/day13/src/com/lc/day13/str01/TestString03.java

@@ -0,0 +1,30 @@
+package com.lc.day13.str01;
+
+/**
+ * ClassName: TestString01
+ *
+ * @Author 爱扣钉-陈晨
+ * @Create 2024/1/9 9:33
+ * @Version 1.0
+ */
+public class TestString03 {
+
+    public static void main(String[] args) {
+        //int indexOf(xx):从前往后找当前字符串中xx,即如果有返回第一次出现的下标,要是没有返回-1
+        // 图片  1.png 截取
+
+        String str = "1.png";
+        int i = str.indexOf(".");
+        System.out.println(i);
+        // "2.3.4.51.png";
+
+        String str2 = "2.3.4.51.png";
+        // lastIndexOf
+
+        int i1 = str2.lastIndexOf(".");
+        System.out.println(i1);
+
+    }
+
+
+}

+ 39 - 0
JavaSE/day13/src/com/lc/day13/str01/TestString04.java

@@ -0,0 +1,39 @@
+package com.lc.day13.str01;
+
+/**
+ * ClassName: TestString01
+ *
+ * @Author 爱扣钉-陈晨
+ * @Create 2024/1/9 9:33
+ * @Version 1.0
+ */
+public class TestString04 {
+
+    public static void main(String[] args) {
+        //int indexOf(xx):从前往后找当前字符串中xx,即如果有返回第一次出现的下标,要是没有返回-1
+        // 图片  1.png 截取
+
+        String str = "1.png";
+        int i = str.indexOf(".");
+        System.out.println(i);
+        // "2.3.4.51.png";
+
+        String str2 = "2.3.4.51.png";
+        // lastIndexOf
+
+        int i1 = str2.lastIndexOf(".");
+        System.out.println(i1);
+
+        //String substring(int beginIndex) :返回一个新的字符串
+        String substring = str2.substring(i1);
+        System.out.println(substring);
+
+        //截取中间部分
+        String s4 = "123abc456";
+        String s5 = s4.substring(3, 6);
+        System.out.println(s5);
+
+    }
+
+
+}

+ 46 - 0
JavaSE/day13/src/com/lc/day13/str01/TestString05.java

@@ -0,0 +1,46 @@
+package com.lc.day13.str01;
+
+import java.util.UUID;
+
+/**
+ * ClassName: TestString01
+ *
+ * @Author 爱扣钉-陈晨
+ * @Create 2024/1/9 9:33
+ * @Version 1.0
+ */
+public class TestString05 {
+
+    public static void main(String[] args) {
+        //char charAt(index):返回[index]位置的字符
+        //char[] toCharArray(): 将此字符串转换为一个新的字符数组返回
+
+        String str = "hello";
+
+        char c = str.charAt(0);
+        System.out.println(c);
+
+        //boolean startsWith(xx):测试此字符串是否以指定的前缀开始
+        boolean b = str.startsWith("h");
+        System.out.println(b);
+
+        //判断 png jpg
+        String fileName = "a.png";
+
+        System.out.println(fileName.endsWith("png"));
+
+        //图片的名称
+
+        System.out.println(UUID.randomUUID().toString());
+
+        String uid = UUID.randomUUID().toString();
+
+        //替换 -
+        String replace = uid.replace("-", "");
+
+        String file = replace + ".png";
+        System.out.println(file);
+    }
+
+
+}

+ 40 - 0
JavaSE/day13/src/com/lc/day13/str02/TestStringBuffer.java

@@ -0,0 +1,40 @@
+package com.lc.day13.str02;
+
+/**
+ * ClassName: TestStringBuffer
+ *
+ * @Author 爱扣钉-陈晨
+ * @Create 2024/1/9 11:34
+ * @Version 1.0
+ */
+public class TestStringBuffer {
+
+    public static void main(String[] args) {
+        StringBuffer sb = new StringBuffer("hello");
+        //调用 链式调用
+        boolean empty = sb.append("world")
+                .append(" java")
+                .substring(3)
+                .isEmpty();
+
+        System.out.println(empty);
+
+        StringBuffer sb1 = new StringBuffer("hello");
+
+        String string = sb1 + "";
+
+        String string1 = sb1.toString();
+
+        //String - StringBuffer
+
+        String s1 = "";
+        //StringBuffer sb2 = s1;
+
+        StringBuffer stringBuffer = new StringBuffer("abcd");
+
+        StringBuffer reverse = stringBuffer.reverse();
+
+        System.out.println(reverse);
+
+    }
+}

+ 24 - 0
JavaSE/day13/src/com/lc/day13/str02/TestStringBuffer1.java

@@ -0,0 +1,24 @@
+package com.lc.day13.str02;
+
+/**
+ * ClassName: TestStringBuffer
+ *
+ * @Author 爱扣钉-陈晨
+ * @Create 2024/1/9 11:34
+ * @Version 1.0
+ */
+public class TestStringBuffer1 {
+
+    public static void main(String[] args) {
+        String str = null;
+        StringBuffer sb = new StringBuffer();
+        sb.append(str);//处理了 null
+        System.out.println(sb.length());// 4
+
+        System.out.println(sb);// null
+
+        StringBuffer sb1 = new StringBuffer(str); // null 处理
+        System.out.println(sb1);// 空指针
+
+    }
+}

+ 43 - 0
JavaSE/day13/src/com/lc/day13/sys07/Test.java

@@ -0,0 +1,43 @@
+package com.lc.day13.sys07;
+
+/**
+ * ClassName: Test
+ *
+ * @Author 爱扣钉-陈晨
+ * @Create 2024/1/9 16:53
+ * @Version 1.0
+ */
+public class Test {
+
+    public static void main(String[] args) {
+
+        long time = System.currentTimeMillis();
+        System.out.println("现在的系统时间距离1970年1月1日凌晨:" + time + "毫秒");
+
+        //System.exit(0);
+
+        System.out.println("over");//不会执行
+
+        String javaVersion = System.getProperty("java.version");
+        System.out.println("java的version:" + javaVersion);
+
+        String javaHome = System.getProperty("java.home");
+        System.out.println("java的home:" + javaHome);
+
+        String osName = System.getProperty("os.name");
+        System.out.println("os的name:" + osName);
+
+        String osVersion = System.getProperty("os.version");
+        System.out.println("os的version:" + osVersion);
+
+        String userName = System.getProperty("user.name");
+        System.out.println("user的name:" + userName);
+
+        String userHome = System.getProperty("user.home");
+        System.out.println("user的home:" + userHome);
+
+        String userDir = System.getProperty("user.dir");
+        System.out.println("user的dir:" + userDir);
+
+    }
+}