Java学习笔记 第五章 常用类

JAVA学习笔记第五章

5.常用类

image-20210518143443274

image-20210518143614274

5.1Integer

image-20210518143824387

image-20210518143948198

image-20210518144446511

image-20210518144459232

image-20210518144650951

image-20210518144744733

image-20210518144817111

image-20210518145103214

image-20210518145841933

valueOf方法的底层

image-20210518145724382

5.2Date

image-20210518150938138

image-20210518151013943

image-20210518151218353

image-20210518151558358

image-20210518151946188

image-20210518152024649

image-20210518152539971

image-20210518152420001

Calendar

image-20210519114235196

image-20210519114358153

image-20210519114542856

练习:

image-20210519114700477

package calendar.code;

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;

/**
 * @Author:wrr
 * @Date:2021/5/19 - 05 - 19 - 11:50 上午
 * @Description:code_train
 */
public class DateShow {
    public static void main(String[] args) {
        Calendar cal = new GregorianCalendar();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你想要查看的日期:(提示请按照例如2019-3-7的格式)");
        try{
            String StrData = sc.next();
            java.sql.Date date = java.sql.Date.valueOf(StrData);
            cal.setTime(date);
            System.out.println("日  一  二  三  四  五  六");
            //System.out.println(date);
            //cal.get(Calendar.DAY_OF_WEEK); //这周的第几天
            int Day_Month = cal.get(Calendar.DAY_OF_MONTH);
            //System.out.println(cal.get(Calendar.DAY_OF_MONTH));  //这个月的第几天
            //System.out.println(cal.getActualMaximum(Calendar.DATE)); //这个月的总天数
            //找到这个月1号是星期几
            int flag = 0;
            int nowDay = cal.get(Calendar.DAY_OF_MONTH); //今天的日期
            cal.set(Calendar.DATE,1); //日期调整为本月的1号
            int num = cal.get(Calendar.DAY_OF_WEEK); //1号前的空格
            for(int i=1;i<num;i++){
                System.out.print('\t');
                flag++;
            }
            for(int i=1; i<=cal.getActualMaximum(Calendar.DATE);i++){
                System.out.print(i);
                if(i==nowDay){
                    System.out.print('*');
                }
                flag++;
                if(flag % 7 == 0){
                    System.out.print('\n');
                }else{
                    System.out.print('\t');
                }
            }
        }catch (Exception e){
            System.out.println(e);
        }

    }
}

结果:

image-20210519192630526

image-20210519204419778

image-20210519204931652

image-20210519205118901

image-20210519205238160

image-20210519205327364

image-20210519205924413

image-20210519210052790

image-20210520114605526

5.3Math

直接使用,不用导包

构造器私有化,不能随便创建对象

image-20210520120106753

image-20210520120208892

image-20210520120538200

image-20210520121854313

image-20210520121722943

5.4String

image-20210520122132979

image-20210520122301879

image-20210520122329885

![image-20210520150229803](../Library/Application Support/typora-user-images/image-20210520150229803.png)

5.4.1equals方法源码

image-20210520150818541

5.4.2compareTo源码

image-20210520151332684

5.4.3字符串常用方法

![image-20210520151554695](../Library/Application Support/typora-user-images/image-20210520151554695.png)

image-20210520151704665

image-20210520151735916

image-20210520151806129

5.4.4字符串内存分析

image-20210520152121305

【2】直接生成字符串:

image-20210520152406831

【3】new关键字创建对象

image-20210520152430311

image-20210520152455273

开辟两块内存空间(字符串常量池的"abc"和堆中开辟的空间)

【4】含有变量的字符串

image-20210520152802621

image-20210520153108939

image-20210520153136481

5.4.5字符串的分类

image-20210520153305674

image-20210520153529863

image-20210520154615234

image-20210520154218674

image-20210520155509257

扩容

image-20210520155402011

image-20210520155654380

image-20210520155757743

SyringBuilder常用方法

image-20210520155934748

image-20210520155955949

StringBuffer源码,同样也是实现AbstractStringBuilder

image-20210520160358575

使用的方法和StringBuilder一样

image-20210520160651438

posted @ 2021-05-20 16:11  wrrr  阅读(59)  评论(0编辑  收藏  举报