zoukankan      html  css  js  c++  java
  • Integert 与 int例子详解

    public final class Integerextends Numberimplements Comparable<Integer>

    Integer 类在对象中包装了一个基本类型 int 的值。Integer 类型的对象包含一个 int 类型的字段。

    此外,该类提供了多个方法,能在 int 类型和 String 类型之间互相转换,还提供了处理 int 类型时非常有用的其他一些常量和方法

    方法:

    public class IngegerorInt {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
    
             System.out.println(Integer.MIN_VALUE);  //-2147483648
             System.out.println(Integer.MAX_VALUE); //2147483647
             System.out.println(Integer.SIZE);    //32
             System.out.println(Integer.BYTES);   //4
             System.out.println(Integer.TYPE);    //int
    
             int a1=2147483647;  //不在在规定范围内,报错:The literal xxx of type int is out of range 
             Integer b1=new Integer(2147483647);
             Integer b2=new Integer(2147483647);
             Integer c1=2147483647;
             Integer c2=2147483647;
             System.out.println(a1==b1); //true   MIN_VALUE-MAX_VALUE范围内为true
             System.out.println(a1==c1); //true
             System.out.println(b1==c1); //false
             System.out.println(b1==b2);  //false
             System.out.println(c1==c2);  //false
             System.out.println();
             System.out.println(b1.equals(a1)); //true   不能 int.equals(Integer)这样比较
             System.out.println(b1.equals(c1)); //true
             System.out.println(c1.equals(b1));  //true
             System.out.println(c1.equals(a1));  //true
             System.out.println();
             System.out.println(b1.equals(b1));  //true
             System.out.println(b1.equals(b2));  //true
             System.out.println(c1.equals(c1));   //true
             System.out.println(c1.equals(c2));   //true
        }
    
    }


  • 相关阅读:
    编程珠玑第二章阅读笔记
    第四周学习进度博客
    python的文件操作
    python通过pymysql实现数据库的增删改查
    python爬取疫情数据详解
    python基本知识点if、while、等等
    apache使用总结
    slf4j的总结
    log4j2使用总结
    安全测试总结
  • 原文地址:https://www.cnblogs.com/tk55/p/8108282.html
Copyright © 2011-2022 走看看