java常用类的使用方法
java常用类的使用方法
Interger:整数类型
1、属性。
static int MAX_VALUE:返回最大的整型数;
static int MIN_VALUE:返回最小的整型数;
static Class TYPE :返回当前类型。
例子:
代码:
System.out.println("Integer.MAX_VALUE: " + Integer.MAX_VALUE );
结果为:Integer.MAX_VALUE: 2147483647
2、构造函数。
Integer(int value) :通过一个int的类型构造对象;
Integer(String s) :通过一个String的类型构造对象;
例子:
代码:
Integer i = new Integer("1234");
生成了一个值为1234的Integer对象。
3、方法。
说明:
1. 所有方法均为public;
2. 书写格式:〔修饰符〕 <返回类型> <方法名(〔参数列表〕)>
如:
static int parseInt(String s) 表示:此方法(parseInt)为类方法(static),返回类型为(int),方法所需参数为String类型。
1. byteValue():取得用byte类型表示的整数;
2. int compareTo(Integer anotherInteger) :比较两个整数。相等时返回0;小于时返回负数;大于时返回正数。
例子:
代码:
Integer i = new Integer(1234);
System.out.println("i.compareTo: " + i.compareTo(new Integer(123)) );
结果为:i.compareTo: 1
3. int compareTo(Object o) :将该整数与其他类进行比较。如果o也为Integer类,进行方法2 的操作;否则,抛出ClassCastException异常。
4. static Integer decode(String nm) :将字符串转换为整数。
5. double doubleValue() :取得该整数的双精度表示。
6. boolean equals(Object obj) :比较两个对象。
7. float floatValue() :取得该整数的浮点数表示。
8. static Integer getInteger(String nm) :根据指定名确定系统特征值。
9. static Integer getInteger(String nm, int val) :上面的重载。
10. static Integer getInteger(String nm, Integer val) :上面的重载。
11. int hashCode() :返回该整数类型的哈希表码。
12. int intValue() : 返回该整型数所表示的整数。
13. long longValue() :返回该整型数所表示的长整数。
14. static int parseInt(String s) :将字符串转换成整数。s必须是时进制数组成,否则抛出NumberFormatException异常。
15. static int parseInt(String s, int radix) :以radix为基数radix返回s的十进制数。所谓的基数,就是“几进制”。
相关文档:
java.io.InputStream的read()方法描述:
If no byte is available because the end of the stream has been reached, the value -1 is returned.
到达流的末尾真会放回-1吗?
......
(本文转载自:http://hi.baidu.com/edilyxin/blog/item/27dc152aba3e10315343c19c.html)
问题的提出:
编译运行下面这个程序会看到什么?
public class Test{
public static  ......
一、不变模式:
一个字符串对象创建后它的值不能改变。
String str1="hello";//创建一个对象hello,不会变;
System.out.println(str1);
str1+=" world!";//两个字符串对象粘粘,系统其实创建了一个新的对象,把Str1的指向改了,指向新的对象;hello就 & ......
在实现singleton模式时,我们有以下几种方法。 1. public static final 字段加上private 的构造函数。 public class Singleton{
public static final Singleton INSTANCE = new Singleton();
......