zoukankan      html  css  js  c++  java
  • int 和 Integer的区别

    int是基本类型,默认值为0,int a=5;a只能用来计算,一般作为数值参数。

    Integer是引用类型,默认值为null, Integer b=5;b是一个对象,它可以有很多方法,一般做数值转换,WEB开发中用。

     应用:list,map中存放的是object,所以不能使用基本数据类型,只能使用引用。

    package com.wangcf;
    
    public class Test {
        /**
         * 俩个Integer都不是new出来的则可以相等,但是必须在-128到127之间
         * int 和Integer不论是否new都相等
         * 只要有new出来的Integer就不会相等
         * @param args
         */
        public static void main(String[] args) {
            int i=1;
            Integer i1=1;
            Integer i5=1;
            Integer i6=1;
            Integer i7=1;
            Integer i2=new Integer(1);
            Integer i3=new Integer(1);
            Integer i4=new Integer(1);
            System.out.println(i==i2);  //true
            System.out.println(i==i1);    //true
            System.out.println(i1==i5); //true 必须在-128到127之间为true,否则为false
            System.out.println(i1==i2);    //false
            System.out.println(i2==i3);    //false
            System.out.println(i3==i4); //false
            System.out.println(i6==i7); //false
        }
    }
  • 相关阅读:
    webservice 使用
    不错的下载网站。
    nvarchar 删除 tab 空格
    easyui juery 使用中发现的问题
    jquery easyui 文档资料
    easyui 合并单元格
    extjs4 中汉字显示不好看存在的问题
    微软语音提示
    一个简单的页面跳转
    导出 sqlsever 到access
  • 原文地址:https://www.cnblogs.com/-beauTiFul/p/6437471.html
Copyright © 2011-2022 走看看