文档详情

第九章.精通常用的java类.ppt

发布:2017-05-28约8.56千字共32页下载文档
文本预览下载声明
BigInteger/BigDecimal java.math包中定义的BigIntegeBigDecimal类型可以分别提供任意长度/精度的整数和浮点数运算功能。 BigInteger类主要方法: * public BigInteger(String val) ?? public static BigInteger valueOf(long val) ?? public BigInteger add(BigInteger val) ?? public BigInteger subtract(BigInteger val) ?? public BigInteger multiply(BigInteger val) ?? public BigInteger divide(BigInteger val) ?? public int compareTo(BigInteger val) ?? public BigInteger remainder(BigInteger val) ?? public BigInteger pow(int exponent) ?? public String toString() NumberFormat/DecimalFormat java.text.NumberFormat/DecimalFormat 提供了将数字格式化为语言环境相关字符串以及逆向解析字符串为数字的功能。 主要方法: * public static final NumberFormat getInstance() public static NumberFormat getInstance(Locale inLocale) public final String format(double number) public static final NumberFormat getCurrencyInstance() public static NumberFormat getCurrencyInstance(Locale inLocale) public static final NumberFormat getPercentInstance() public static NumberFormat getPercentInstance(Locale inLocale) 第九章 精通常用java类 本章目标 java.lang.Object类 字符串相关类型 封装类 日期/时间相关类型 数学相关类型 * Object类 java.lang.Object类是所有Java类的最高层次父类,该类提供了面向对象编程技术的基本机制。 重要方法列表: hashCode()方法 toString()方法 equals()方法 finalize()方法 clone()方法 wait()方法 notify()/notifyAll()方法 * hashCode()方法 * public class QQ{ private int account; public QQ(int account){ this.account = account; } //… } public class TestHashCode{ public static void main(String[] args){ QQ q1 = new QQ(3715500); QQ q2 = new QQ; int handle1 = q1.hashCode(); System.out.println(handle1); System.out.println(Integer.toHexString(handle1)); System.out.println(q1); System.out.println(----------------); System.out.println(q2.hashCode()); } } toString()方法 方法格式:public String toString() { …} 方法功能:以字符串形式返回当前对象的有关信息,在Object类的原始定义中,所返回的是对象所属的类型名称及其哈希码。 当使用System.out.println()方法直接打印输出引用类型变量时,println()方法中会先自动调用其toString()方法,再将所返回的字符串信息输出。 在进行String与其它类型数据的连接操作时,自动调用toString()方法,基本类型数据转换为String类型时,调用了对应封装类的toString()方法。 可以根据需要在用户定义类型中重写toString()方法。 * 重写toString()方法 * p
显示全部
相似文档