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
        }
    
    }


  • 相关阅读:
    在Linux中安装Oracle(较详细图解)
    SecureCRT
    MHA配置文件说明
    MySQL建表规范与常见问题 (go)
    Shell编程时常用的系统文件(转)
    Leetcode: Excel Sheet Column Title
    Leetcode: Find Peak Element
    Leetcode: Intersection of Two Linked Lists
    Leetcode: Majority Element
    Summary: Class Variable vs. Instance Variable && Class Method
  • 原文地址:https://www.cnblogs.com/tk55/p/8108282.html
Copyright © 2011-2022 走看看