zoukankan      html  css  js  c++  java
  • 包装类、及装箱和拆箱

    包装类是一种特殊的类,在java 的lang包中。用来将八种基本数据类型包装为对象。

    以下是基本数据类型与包装类的对应关系:

    byte Byte;short Short;int Integer;long Long;float Float;double Double;char Charactor;boolean Boolean。

    各种包装类的构造器和适用方法都很类似,下面以最常用的Integer包装类做示例。

    构造器:

    Integer(int i): 将int类型数据i包装成Integer类对象

    Integer(String s): 将字符串s包装成Integer类对象。注意:s必须是整数字符串类型。

    常用方法:

    Static int    parseInt(String s):类方法,将字符串转换为整型数据

    eg:int i=Integer.parseInt("15")

    int  intValue():计算包装类对象的值

    eg:Integer a=new Integer("12");

          int i=a.intValue()

    static String     toHexString(int i):类方法,将一个整数转换为16进制字符串

     eg:

         String str=Integer.toHexString(17)

    String   toString():将包装类对象转换为字符串

    eg:

        Integer b=12;//装箱

       String str=b.toString();

    static Integer  valueOf(int i):类方法,将整数转化为包装类对象

    eg: Integer a=Integer.valueOf(7);

    装箱:

    Integer a=12;//装箱是快捷将int数据转化为包装类对象

    拆箱

    Integer b=9;

    int a=b;//拆箱将包装类对象转换为整数。

  • 相关阅读:
    解决vue项目route使用history模式,tomcat部署刷新url 404问题
    更新
    Mac Anaconda 安装
    Mac python 环境配置
    Mac Python PyQt5 环境搭建
    Python 百分比计算
    Python __init__.py 文件使用
    Python redis 简单介绍
    python Django 创建应用
    python Django 项目创建
  • 原文地址:https://www.cnblogs.com/hitnmg/p/9346638.html
Copyright © 2011-2022 走看看