zoukankan      html  css  js  c++  java
  • 基本类型的包装类

    基本类型的包装类

    基本类型不是对象,所以Java针对基本类型提供了对应的包装类,以对象的形式来使用

    byte->Byte|short->Short|int->Integet|long->Long|char->Character|double->Double|boolean->Boolean

    装箱 :基本类型转包装类型

    拆箱 :包装类型转换成基本类型

    成员方法

    static 基本类型 parseXxx(String): 将字符串类型的数据转换成对应的基本类型

    Character没有parseXxx方法,因为字符串想转换成char类型的数据,可以通过String类中的toCharArray方法,charAt()

    package com.wang.basetype;
    public class Demo01 {
        public static void main(String[] args) {
            //将基本类型转换为引用类型
            Integer i1=new Integer(30);
            //将引用类型转换为基本类型
            int b=i1.intValue();
            System.out.println(b);
            System.out.println("============================");
            //自动拆装箱
            Integer i2=20;
            int c=i2;
            //static 基本类型 parseXxx(String): 将字符串类型的数据转换成对应的基本类型
            //将字符串类型的10转换成int类型的10
            String s="20";
            int i=Integer.parseInt(s);
            System.out.println("i="+i);
            System.out.println("i+2="+(i+2));
            byte b1=Byte.parseByte(s);
            System.out.println("b1:"+b1);
            double d=Double.parseDouble(s);
            System.out.println("d:"+d);
            long l=Long.parseLong(s);
            System.out.println("l+70="+(l+70));
            boolean b2=Boolean.parseBoolean(s);
            System.out.println(b2);
        }
    }
  • 相关阅读:
    一条软件缺陷(或者叫 Bug)记录都包含了哪些内容?如何提交高质量的软件缺陷(Bug)记录?
    测试人员在软件开发过程中的任务
    HDOJ1754(线段树)
    HDOJ1166(线段树,树状数组)
    分治法
    POJ1840(哈希)
    HOOJ1290 2050(递推)
    POJ1035(字符串)
    HDOJ1800(哈希)
    POJ2299(归并排序)
  • 原文地址:https://www.cnblogs.com/wyj96/p/11772071.html
Copyright © 2011-2022 走看看