java韩顺平学习笔记7 (八大包装类)

java韩顺平学习笔记7 (八大包装类)

image-20230803124117918

装箱和拆箱

image-20230803143818615

//手动装箱  int->InTeger
int n1 =10;
Integer integer = new Integer(n1);			//1.	
Integer inTeger2 = Integer.valueOf(n1);		//2.

//手动拆箱 Integer->int
Integer j = new InTeger(99);
int j1 = j.intValue();			
//自动装箱
int n2=100;
Integer integer1= n2;		//底层使用的是Integer.valueOf()
//自动拆箱
int n3 = integer1;			//底层使用的是	intValue();	

String类

  • 创建S听对象的两种方式
  1. 方式一
String s= "lu";
  1. 方式二
String s= new String("lu");
  • 区别

image-20230803172640505

  • 习题

image-20230803172547102

字符串特性

image-20230803231609166

String类常用方法

image-20230803232742392

StringBuffer类

  • String的区别

image-20230804113634889

  • String->StringBuffer 转换
String str = "hello"
StringBuffer stringBuffer = new StringBuffer(str);	//使用构造器,对str本身没有影响
  • StringBuffer->String 转换
StringBuffer stringBuffer = new StringBuffer("hello")
String s = stringBuffer.toString();			//toString()方法
String S1 = new String(stringBuffer);		//构造器

StringBuffer方法

image-20230804172854012

Arrays类

image-20230805112034550

sort方法使用匿名内部类定制排序顺序

image-20230805114638857

System类

image-20230806134430758

Date类

image-20230806155157903

用于格式化的类SimpleDateFormat

image-20230806155925162

  • Date实例,显示指定格式日期
public static void main(String[] args) {
        Date date = new Date();
        DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String s = df2.format(date);		//格式转换
        System.out.println(s);
    }

Calendar类(第二代日期)(被优化了)

提供单例字段,不提供格式化功能,自己拼接

public static void main(String[] args) {
        Calendar calendar = Calendar.getInstance();
        System.out.println(calendar);		
        System.out.println("年:" + calendar.get(Calendar.YEAR));				//显示年
        System.out.println("月:" + (calendar.get(Calendar.MONTH)+1));		//显示月
    }

image-20230806163713748

第三代日期类

  • LocalDate(日期,年月日)
  • LocalTime(时间,时分秒)
  • LocalDateTime(日期时间)
  public static void main(String[] args) {
        LocalDate ld1 = LocalDate.now();
        System.out.println("日期:"+LocalDate.now());
        System.out.println("日期+时间:"+LocalDateTime.now());
        System.out.println("时间:"+ LocalTime.now());
        System.out.println("年份" + ld1.getYear());      //获取年份字段
    }

image-20230806164908809

格式化DateTimeFormatter

//创建对象=定义 格式
DateTimeFormatter dt = DateTimeFormatter.ofPattern("yyyy年-MM月-dd日 HH:mm:ss");
LocalDate ld1 = LocalDate.now();
String s = dt.format(ld1);		//获取时间,然后格式化后返回结果
System.out.println(s);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值