Integer是Java类库中包装有各种功能的类, int 是Java语言中内置
的数据类型, 怎么能一样?
的数据类型, 怎么能一样?
解决方案 »
- 关于Iterator的问题,请教高手。。。
- "Statement语句级别"是什么意思?
- 散分....祝大家新春快乐^_^
- !·#!·#!#··#·怎么回事呀!!
- 在使用JDBC连接SQL Server 2000时发现无法使用getObject方法检索real类型的数据,这是为什么,请教各位大虾!
- 为什么我的程序在执行时会自动退出呢
- 谁知到哪里有关于JFileChooser的文档
- 欢迎光临,一定给分
- 很简单的程序:Exception in the thread "main" ClassNotFound:Demo
- 急外包JAVA项目
- 把xx.addEventListener(this);放到类的函数中,而不是构造函数,参数该是什么?谢谢!
- 建国53周年,举国同庆! 发“分”图强!
Integer是继承自Object的
所以Integer封装了很多方法,比如一些static的工具性方法
Integer n=new Integer(47);与int n=47;两种赋值是否一样的,即便Integer类有更多的方法又怎么了, 是否可以把 Integer n=new Integer(47)理解为Integer类的一种赋值形式?我是菜鸟,也请各位能解释的详细一点吧,如果不同的话
Integer n=new Integer(47);n是一个对象 n继承Number, Number继承Object n为Object所以它具有对象的一些属性和方法。
而int n=47;n为类型。 不具备对象的一些属性和方法。
通常我们建议使用n=47定义一个整数。但在java的很多方法中参数或返回值为Object 这个使用就要使用Integer n=new Integer(47);定义
Integer的构造函数是这样的
public Integer(int value) {
this.value = value;
}
然后,Integer封装了很多int和其他类型转换等常用方法
比如toUnsignedString和compareTo private static String toUnsignedString(int i, int shift) {
char[] buf = new char[32];
int charPos = 32;
int radix = 1 << shift;
int mask = radix - 1;
do {
buf[--charPos] = digits[i & mask];
i >>>= shift;
} while (i != 0); return new String(buf, charPos, (32 - charPos));
}
public int compareTo(Integer anotherInteger) {
int thisVal = this.value;
int anotherVal = anotherInteger.value;
return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1));
}
两个东西各有各的用处。