常用类的使用方法

常用类的使用方法 :
nterger:整数类型
1、属性。
代码:
System.out.println(“Integer.MAX_VALUE: ” + Integer.MAX_VALUE );
结果为:Integer.MAX_VALUE: 2147483647
2、构造函数。
代码:
Integer i = new Integer(“1234”);
生成了一个值为1234的Integer对象。
3、方法。
说明:
1. 所有方法均为public;
2. 书写格式:[修饰符] <返回类型> <方法名([参数列表])>
如:
static int parseInt(String s) 表示:此方法(parseInt)为类方法(static),返回类型为(int),方法所需参数为String类型。

代码:

Integer i = new Integer(1234);
System.out.println(“i.compareTo: ” + i.compareTo(new Integer(123)) );
结果为:i.compareTo: 1

代码:

String s1 = new String(“1010”);
System.out.println(“Integer.parseInt(String s, int radix): ” + Integer.parseInt(s1,2) );
结果为:Integer.parseInt(String s, int radix): 10

代码:
int i1 = 54321;
System.out.println(“Integer.toString(int i, int radix): ” + Integer.toString(i1,16) );
结果为:Integer.toString(int i, int radix): d431
static int MAX_VALUE:返回最大的整型数;
static int MIN_VALUE:返回最小的整型数;
static Class TYPE :返回当前类型。

例子:

Integer(int value) :通过一个int的类型构造对象;
Integer(String s) :通过一个String的类型构造对象;

例子:

  1. byteValue():取得用byte类型表示的整数;
  2. int compareTo(Integer anotherInteger) :比较两个整数。相等时返回0;小于时返回负数;大于时返回正数。

例子:

  1. int compareTo(Object o) :将该整数与其他类进行比较。如果o也为Integer类,进行方法2 的操作;否则,抛出ClassCastException异常。
  2. static Integer decode(String nm) :将字符串转换为整数。
  3. double doubleValue() :取得该整数的双精度表示。
  4. boolean equals(Object obj) :比较两个对象。
  5. float floatValue() :取得该整数的浮点数表示。
  6. static Integer getInteger(String nm) :根据指定名确定系统特征值。
  7. static Integer getInteger(String nm, int val) :上面的重载。
  8. static Integer getInteger(String nm, Integer val) :上面的重载。
  9. int hashCode() :返回该整数类型的哈希表码。
  10. int intValue() : 返回该整型数所表示的整数。
  11. long longValue() :返回该整型数所表示的长整数。
  12. static int parseInt(String s) :将字符串转换成整数。s必须是时进制数组成,否则抛出NumberFormatException异常。
  13. static int parseInt(String s, int radix) :以radix为基数radix返回s的十进制数。所谓的基数,就是“几进制”。

例子:

  1. short shortValue() :返回该整型数所表示的短整数。
  2. static String toBinaryString(int i) :将整数转为二进制数的字符串。
  3. static String toHexString(int i) :将整数转为十六进制数的字符串。
  4. static String toOctalString(int i) :将整数转为八进制数的字符串。
  5. String toString() :将该整数类型转换为字符串。
  6. static String toString(int i) :将该整数类型转换为字符串。不同的是,此为类方法。
  7. static String toString(int i, int radix) :将整数i以基数radix的形式转换成字符串。

例子:

  1. static Integer valueOf(String s) :将字符串转换成整数类型。
  2. static Integer valueOf(String s, int radix) :将字符串以基数radix的要求转换成整数类型。

Float:实数类型

1、属性。

  1. static float MAX_VALUE : 返回最大浮点数,在不同硬件平台中由Float.intBitsToFloat(0x7f7fffff)计算得出。
  2. static float MIN_VALUE : 返回最小浮点数,在不同硬件平台中由Float.intBitsToFloat(0x1)计算得出。
  3. static float NaN : 表示非数值类型的浮点数,在不同硬件平台中由
  4. Float.intBitsToFloat(0x7fc00000)计算得出。
  5. static float NEGATIVE_INFINITY:返回负无穷浮点数,在不同硬件平台中由Float.intBitsToFloat(0xff800000)计算得出。
  6. static float POSITIVE_INFINITY :返回正无穷浮点数,在不同硬件平台中由Float.intBitsToFloat(0x7f800000)计算得出。
  7. static Class TYPE :返回当前类型。

2、构造函数。

Float(double value) :以double类型为参数构造Float对象。
Float(float value) :以Float类型为参数构造Float对象。
Float(String s) :以String类型为参数构造Float对象。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值