zoukankan      html  css  js  c++  java
  • JavaSE 高级 第1节 基本数据类型的封装类

    2016-07-05

    1,如何查看API

    2,byte Byte
    char Character
    short Short
    int Integer
    long Long
    float Float
    double Double
    boolean Boolean

    3,自动装箱与拆箱
    基本数据类型 转换为 封装类型:装箱
    封装类型 转换为 基本类型:拆箱

    拆箱示例:
    Integer i1=new Integer(10);
    int i2=i1;

    装箱示例:
    int i3=9;
    Integer i4=i3;

    package com.java1995;
    
    public class TestBoolean {
        
        public static void main(String[] args) {
            Boolean b1=new Boolean("true");
            System.out.println(b1.toString());
            
            Boolean b2=new Boolean(false);
        }
    
    }
    package com.java1995;
    
    public class TestDouble {
        
        public static void main(String[] args) {
            System.out.println("Double的最大值:"+Double.MAX_VALUE);
            System.out.println("Double的最小值:"+Double.MIN_VALUE);
            double d=Double.parseDouble("123");
            System.out.println(d);
            System.out.println(Double.POSITIVE_INFINITY);
            System.out.println(Double.NEGATIVE_INFINITY);
        }
    
    }

    package com.java1995;
    
    public class TestInteger {
        
        public static void main(String[] args) {
            System.out.println("Integer的最大值:"+Integer.MAX_VALUE);
            System.out.println("Integer的最小值:"+Integer.MIN_VALUE);
    
            int i=Integer.parseInt("123");
            System.out.println(i);
    
            String s=Integer.toBinaryString(10);    
            System.out.println(s);
        }
    
    }

    package com.java1995;
    
    public class Test {
        public static void main(String[] args) {
            //自动拆箱
            Integer i1=new Integer(10);
            int i2=i1;
            System.out.println(i2);
            //自动装箱
            int i3=9;
            Integer i4=i3;
            System.out.println(i4);
        }
    
    }

    【参考资料】

    [1] Java轻松入门经典教程【完整版】

  • 相关阅读:
    【翻译九】java-同步方法
    【翻译八】java-内存一致性错误
    【翻译七】java-同步
    【翻译六】java-连接和实例
    【翻译五】java-中断机制
    【翻译四】java-并发之线程暂停
    [topcoder]TheGridDivTwo
    [topcoder]TheConsecutiveIntegersDivOne
    [leetcode]Maximum Product Subarray
    [leetcode]Find Minimum in Rotated Sorted Array
  • 原文地址:https://www.cnblogs.com/cenliang/p/5642504.html
Copyright © 2011-2022 走看看