怎么把string类型封装成datetime_基本类型包装类概述

v2-b960be871ee847cb6c2fea0db4c4fb93_1440w.jpg?source=172ae18b

基本类型包装类概述

将基本数据类型封装成对象的好处在于可以在对象中定义更多的功能方法操作该数据。

常用的操作之一:用于基本数据类型与字符串之间的转换

基本数据类型包装类
byteByte
intInteger
shortShort
longLong
floatFloat
doubleDouble
charCharacter
booleanBoolean

91dc757347dbca12ac26028a7d6d43c8.png

Integer类的概述和使用

Integer:包装一个对象中的原始类型int的值

方法名说明
Public Integer(int value)根据int值创建Integer对象(过时)
Public Integer(string s)根据string值创建Integer对象(过时)
Public static Integer valueOf(int i)返回表示指定的int值的Integer实例
Public static Integer valueOf(string s)返回一个保存指定的值的Integer对象string

例子:调用Integer类型看int与字符串string

//创建我们的Integer类

public class Sunday {

public static void main(String[] args){

Integer i1=Integer.valueOf(100); //返回表示指定的int值的Integer实例

System.out.println(i1);

Integer i2=Integer.valueOf("100");//返回一个保存指定的值的Integer对象string

System.out.println(i2);

}

}

Output result:

100

100

从结果来看这两个方法都是一样的输出整数100.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值