个人做网站能备案吗,卖网站模板,上海房产交易中心官网,cdr做网站流程在Java中不能自己定义基本数据类型对象#xff0c;为了将基本数据类型视为对象进行处理#xff0c;并能连接相关方法#xff0c;Java为每个基本数据类型都提供了【包装类】如int型数值的包装类【Integer】,boolean型数值的包装类【Boolean】,这样就可以把这些基本数据类型转…
在Java中不能自己定义基本数据类型对象为了将基本数据类型视为对象进行处理并能连接相关方法Java为每个基本数据类型都提供了【包装类】如int型数值的包装类【Integer】,boolean型数值的包装类【Boolean】,这样就可以把这些基本数据类型转换为对象来处理了。 java.lang包中的Integer类Long类Short类可以将基本数据类型int,long,short封装成一个类这些类都是Number的子类区别就是封装了不同的数据类型。
1.Integer
Integer类在对象中包装了一个基本类型int的值该类的对象包含一个int类型的字段此外该类提供了多种方法能 在int类型和String类型之间互相转换。
1.1构造方法 Integer类有2种构造方法 1.1.1 Integer(int number) 以int型变量为参数创建Integer对象。 Integer number new Integer(7); 1.1.2 Integer(String str) 以String型变量为参数创建Integer对象。 Integer number new Integer(45); 1.2 常用方法
Integer类的常用方法 方法返回值功能描述Integer.byteValue()byte以byte类型返回该Integer的值Integer.shortValue()short以short类型返回该Integer的值Integer.intValue()int以int类型返回该Integer的值Integer.toString()String返回一个表示该Integer值的String对象Integer.valueOf(String str)Integer返回保存指定String值的Integer对象Integer.parseInt(String str)int返回包含在由str指定的字符串中的数字的等价整数型Integer.compareTo(Integer anotherInteger)int在数字上比较2个Integer对象如果这2个对象相等则返回0如果调用对象的数值小于anotherInteger的数值则返回负值如果调用对象的数值大于anotherInteger的数值则返回正值Integer.equals(Object IntegerObj)boolean比较此对象与另一个对象是否相等
package classInfo;public class summation {public static void main(String[] args) {String[] str {89, 12, 10, 18, 35};int sum 0;//实现将String数组的原酸都转换为int型for (int i 0; i str.length; i) {int myInt Integer.parseInt(str[i]);sum sum myInt;}System.out.println(String数组中的各元素之和 sum);}
}输出String数组中的各元素之和164
package classInfo;public class Charac {public static void main(String[] args){String str1 Integer.toString(456); //将Integer对象转换为十进制字符串表示String str2 Integer.toBinaryString(456); //将Integer对象转换为二进制表示String str3 Integer.toHexString(456); //将Integer对象转换为十六进制表示String str4 Integer.toOctalString(456); //将Inter对象转换为八进制表示System.out.println(456的十进制表示为str1);System.out.println(456的二进制表示为str2);System.out.println(456的十六进制表示为str3);System.out.println(456的八进制表示为str4);}
}输出456的十进制表示为456456的二进制表示为111001000456的十六进制表示为1c8456的八进制表示为7101.3 常量 Integer类提供了4个常量 1.3.1 MAX_VALUE 表示int类型可取的最大值即2^31 -1。 1.3.2 MIN_VALUE 表示int类型可取的最小值即-2^31。 1.3.3 SIZE 用来以二进制补码形式表示int值的位数。 1.3.4 TYPE 表示基本类型int的class实例。
package classInfo;public class GetCon {public static void main(String[] args){int maxInt Integer.MAX_VALUE; //获取int类型的可取最大值int minInt Integer.MIN_VALUE; //获取int类型的可取最小值int intSize Integer.SIZE; //获取int类型的二进制位数System.out.println(int类型可取最大值是maxInt);System.out.println(int类型可取最小值是minInt);System.out.println(int类型的二进制位数是intSize);}
}输出int类型可取最大值是2147483647int类型可取最小值是-2147483648int类型的二进制位数是32 2.Boolean
Boolean类将基本类型为boolean的值包装在一个对象中一个Boolean类型的对象只包含一个类型为boolean的字段此外Boolean类还为boolean何String的相互转换提供了许多方法。
2.1 构造方法 2.1.1 Boolean(boolean value) 创建一个表示value参数的Boolean对象 Boolean b new Boolean(true); 2.1.2 Boolean(String str) 创建一个以String变量为参数的Boolean对象如果String参数不为null且忽略大小写时等于true,则分配一个表示true值的Boolean对象否则获得一个false值的Boolean对象。 Boolean bool new Boolean(ok); package classInfo;public class GetBoolean {public static void main(String[] args) {Boolean b1 new Boolean(true); //输出trueBoolean b2 new Boolean(True); //输出trueBoolean b3 new Boolean(null); //输出falseBoolean b4 new Boolean(ok); //输出falseBoolean b5 new Boolean(1); //输出falseSystem.out.println(b1);System.out.println(b2);System.out.println(b3);System.out.println(b4);System.out.println(b5);}
}输出truetruefalsefalsefalse
2.2 常用方法
Boolean类的常用方法 方法返回值功能描述Boolean.booleanValue()boolean将Boolean对象的值以对应的boolean值返回Boolean.equals(Object obj)boolean判断调用该方法的对象与obj是否相等。当且仅当参数不为null,且与调用该方法的对象一样都表示同一个boolean值的Boolean对象是才返回trueBoolean.parseBoolean(String str)boolean将字符串参数解析成boolean值Boolean.toString()String返回表示该boolean值的String对象Boolean.valueOf(String str)boolean返回一个指定的字符串表示值的boolean值
package classInfo;import com.sun.org.apache.xpath.internal.operations.Bool;public class GetBoolean {public static void main(String[] args) {Boolean b1 new Boolean(true); //创建Boolean对象Boolean b2 new Boolean(ok); //创建Boolean对象System.out.println(b1: b1.booleanValue());System.out.println(b2: b2.booleanValue());}
}输出b1:trueb2:false
2.3 常量 Boolean提供了3个常量: 2.3.1 TRUE 对应基值true的Boolean对象 2.3.2 FALSE 对应基值false的Boolean对象 2.3.3 TYPE 基本类型boolean的class对象 3.Byte
Byte类将基本类型为byte的值包装在一个对象中一个Byte类型的对象只包含一个类型为byte的字段此外Byte类还为byte和String的互转提供了方法。
3.1 构造方法 Byte类提供了2种构造方法的重载形式来创建Byte类对象。 3.1.1 Byte(byte value) 以byte型变量为参数创建Byte对象 byte mybyte 45; Byte b new Byte(mybyte); 3.1.2 Byte(String str) 以String型变量为参数创建Byte对象 Byte b new Byte(12); 3.2 常用方法
Byte类的常用方法 方法返回值功能描述Byte.byteValue()byte以一个byte值返回Byte的对象Byte.intValue()int以一个int值返回Byte对象Byte.doubleValue()double以一个double值返回此Byte的值Byte.valueOf(String str)byte返回一个保持指定String所给出的值Byte对象Byte.toString()String返回表示此Byte的值的String对象Byte.equals(Object obj)boolean将此对象与指定对象比较如果此对象与obj相等则返回true,否则返回falseByte.parseByte(String str)byte将String型参数解析成等价的字节(byte)形式Byte.compareTo(Byte anotherByte)int在数字上比较两个Byte对象如果这2个对象相等则返回0如果调用对象的数值小于anotherByte的数值则返回负值如果调用对象的数值大于anotherByte的数值则返回正值
3.3 常量 Byte类中提供4个常量 3.3.1 MIN_VALUE byte类型可取的最小值 3.3.2 MAX_VALUE byte类型可取的最大值 3.3.3 SIZE 用于二进制补码形式表示byte值的位数 3.3.4 TYPE 表示基本类型byte的class实例 4.Character
Character类在对象中包装一个基本类型为char的值一个Character类型的对象包含类型为char的单个字段该类提供了几种方法以确定字符的类别大小写字母数字等并将字符从大写转换成小写从小写转换成大写。
4.1 构造方法 4.1.1 Character(char value) 该类的构造函数必须是一个char类型的数据。通过该构造函数创建的Character类对象包含由char类型参数提供的值一旦Character类被创建它包含的数值就不能改变了。 Character mychar new Character(s); 4.2 常用方法
Character类的常用方法 方法返回值功能描述Character.charValue()char返回此Character对象的值Character.compareTo(Character anotherCharacter)int在数字上比较两个Character对象如果这2个对象相等则返回0如果调用对象的数值小于anotherCharacter的数值则返回负值如果调用对象的数值大于anotherCharacter的数值则返回正值Character.equals(Object obj)boolean将调用该方法的对象与指定对象相比较是否想相等Character.toString()String返回一个表示指定char值的String对象Character.toUpperCase(char ch)char将字符参数转换为大写Character.toLowerCase(char ch)char 将字符参数转为小写Character.isUpperCase(char ch)boolean判断指定字符是否为大写字符Character.isLowerCase(char ch)boolean判断指定字符是否为小写字符
package classInfo;public class UpperOrLower {public static void main(String[] args) {Character mychar1 new Character(A); //声明Character对象Character mychar2 new Character(a);System.out.println(mychar1 是大写字母吗: Character.isUpperCase(mychar1));System.out.println(mychar2 是小写字母吗 Character.isLowerCase(mychar2));}
}输出A是大写字母吗:truea是小写字母吗true
4.3 常量 Character提供了大量表示特定字符的常量。 4.3.1 CONNECTOR_PUNCTUATION 返回byte型值表示Unicode规范中的常规类别”Pc. 4.3.2 UNASSIGNED 返回byte型值表示Unicode规范中的常规类别“Cn”。 4.3.3 TITLECASE_LETTER 返回byte型值表示Unicode规范中的常规类别“Lt”。 5.Double/Float
Double和Float包装类是对double,float基本类型的封装他们都是Number类的子类又都是对小数进行操作所以常用方法基本相同。 Double类在对象中包装一个基本类型为double的值。每个Double类的对象都包含一个double类型的字段此外该类还提供多个方法可以将double转换为String,也可以将String转换为double.
5.1 构造方法 Double类提供了2中构造方法来获得Double类对象 5.1.1 Double(double value) 基于double参数创建Double对象。 5.1.2 Double(String str) 用字符串表示的double类型的浮点值来创建Double对象。
5.2 常用方法
Double类的常用方法 方法返回值功能描述Double.byteValue()byte以byte形式返回Double对象的值(强制转换)Double.intValue()int以int形式返回Double对象的值Double.longValue()long以long形式返回Double对象的值Double.doubleValue()double以doulbe形式返回Double对象的值Double.compareTo(Double d)int在数字上比较两个Double对象如果这2个对象相等则返回0如果调用对象的数值小于Double的数值则返回负值如果调用对象的数值大于Double的数值则返回正值Double.equals(Object obj)boolean将此对象与指定的对象比较Double.valueOf(String str)Double返回保存用参数字符串str表示的double值的Double对象Double.toString()String返回此对象的字符串表示形式Double.isNaN()boolean如果此double值是非数字值(NaN)则返回true;否则返回false;
5.3 常量 Double类提供了一下常量 5.3.1 MAX_EXPONENT 返回int值表示有限double变量可能具有的最大指数。 5.3.2 MIN_EXPONENT 返回int值表示有限double变量可能具有的最小指数。 5.3.3 NEGATIVE_INFINITY 返回double值表示保存double类型的负无穷大值的常量。 5.3.4 POSITIVE_INFINITY 返回double值表示保存double类型的正无穷大值的常量。 6.Number 抽象类【Number】是BigDecimal、BigInteger、Byte、Short、Integer、Long、Float、Double类的父类Number的子类必须提供将表示的数值转换为byte、short、int、long、float、double的方法例如doubleValue()方法返回双精度值floatValue()方法返回浮点值。
6.1 Number类的方法
Number类的方法 方法返回值功能描述Number.byteValue()byte以byte形式返回指定的数值Number.shortValue()short以short形式返回指定的数值Number.intValue()int以int形式返回指定的数值Number.longValue()long以long形式返回指定的数值Number.floatValue()float以float形式返回指定的数值Number.doubleValue()double以double形式返回指定的数值 Number类的方法分别被Number的各子类所实现也就是说Number类的所有子类中都包含以上几种方法。 文章转载自: http://www.morning.kfyqd.cn.gov.cn.kfyqd.cn http://www.morning.wskn.cn.gov.cn.wskn.cn http://www.morning.ptqbt.cn.gov.cn.ptqbt.cn http://www.morning.pjwfs.cn.gov.cn.pjwfs.cn http://www.morning.wqmyh.cn.gov.cn.wqmyh.cn http://www.morning.wdjcr.cn.gov.cn.wdjcr.cn http://www.morning.qnftc.cn.gov.cn.qnftc.cn http://www.morning.grbp.cn.gov.cn.grbp.cn http://www.morning.lqlfj.cn.gov.cn.lqlfj.cn http://www.morning.rkmsm.cn.gov.cn.rkmsm.cn http://www.morning.kyjpg.cn.gov.cn.kyjpg.cn http://www.morning.hqbk.cn.gov.cn.hqbk.cn http://www.morning.wxlzr.cn.gov.cn.wxlzr.cn http://www.morning.qcbhb.cn.gov.cn.qcbhb.cn http://www.morning.zkqsc.cn.gov.cn.zkqsc.cn http://www.morning.sthgm.cn.gov.cn.sthgm.cn http://www.morning.bnpn.cn.gov.cn.bnpn.cn http://www.morning.3jiax.cn.gov.cn.3jiax.cn http://www.morning.fksyq.cn.gov.cn.fksyq.cn http://www.morning.sffkm.cn.gov.cn.sffkm.cn http://www.morning.cjcry.cn.gov.cn.cjcry.cn http://www.morning.cdrzw.cn.gov.cn.cdrzw.cn http://www.morning.hwprz.cn.gov.cn.hwprz.cn http://www.morning.mgfnt.cn.gov.cn.mgfnt.cn http://www.morning.xqbbc.cn.gov.cn.xqbbc.cn http://www.morning.lwtfr.cn.gov.cn.lwtfr.cn http://www.morning.tpfny.cn.gov.cn.tpfny.cn http://www.morning.xtqld.cn.gov.cn.xtqld.cn http://www.morning.ypzr.cn.gov.cn.ypzr.cn http://www.morning.xkqjw.cn.gov.cn.xkqjw.cn http://www.morning.fqljq.cn.gov.cn.fqljq.cn http://www.morning.jzykq.cn.gov.cn.jzykq.cn http://www.morning.rpms.cn.gov.cn.rpms.cn http://www.morning.xdfkrd.cn.gov.cn.xdfkrd.cn http://www.morning.zlff.cn.gov.cn.zlff.cn http://www.morning.cxsdl.cn.gov.cn.cxsdl.cn http://www.morning.dbtdy.cn.gov.cn.dbtdy.cn http://www.morning.dbddm.cn.gov.cn.dbddm.cn http://www.morning.blbys.cn.gov.cn.blbys.cn http://www.morning.ktrzt.cn.gov.cn.ktrzt.cn http://www.morning.slfkt.cn.gov.cn.slfkt.cn http://www.morning.fpkpz.cn.gov.cn.fpkpz.cn http://www.morning.xlxmy.cn.gov.cn.xlxmy.cn http://www.morning.ftmp.cn.gov.cn.ftmp.cn http://www.morning.jfjqs.cn.gov.cn.jfjqs.cn http://www.morning.xjnjb.cn.gov.cn.xjnjb.cn http://www.morning.txtzr.cn.gov.cn.txtzr.cn http://www.morning.slkqd.cn.gov.cn.slkqd.cn http://www.morning.tzcr.cn.gov.cn.tzcr.cn http://www.morning.smwlr.cn.gov.cn.smwlr.cn http://www.morning.pmptm.cn.gov.cn.pmptm.cn http://www.morning.rhdqz.cn.gov.cn.rhdqz.cn http://www.morning.ntkpc.cn.gov.cn.ntkpc.cn http://www.morning.swkzk.cn.gov.cn.swkzk.cn http://www.morning.kbqqn.cn.gov.cn.kbqqn.cn http://www.morning.pdwzr.cn.gov.cn.pdwzr.cn http://www.morning.lmjkn.cn.gov.cn.lmjkn.cn http://www.morning.tcylt.cn.gov.cn.tcylt.cn http://www.morning.yswxq.cn.gov.cn.yswxq.cn http://www.morning.gagapp.cn.gov.cn.gagapp.cn http://www.morning.fygbq.cn.gov.cn.fygbq.cn http://www.morning.qymqh.cn.gov.cn.qymqh.cn http://www.morning.gwsdt.cn.gov.cn.gwsdt.cn http://www.morning.khclr.cn.gov.cn.khclr.cn http://www.morning.gllhx.cn.gov.cn.gllhx.cn http://www.morning.pbmkh.cn.gov.cn.pbmkh.cn http://www.morning.bxgpy.cn.gov.cn.bxgpy.cn http://www.morning.ldcrh.cn.gov.cn.ldcrh.cn http://www.morning.skcmt.cn.gov.cn.skcmt.cn http://www.morning.qmnhw.cn.gov.cn.qmnhw.cn http://www.morning.znqxt.cn.gov.cn.znqxt.cn http://www.morning.sskns.cn.gov.cn.sskns.cn http://www.morning.jxlnr.cn.gov.cn.jxlnr.cn http://www.morning.ztdlp.cn.gov.cn.ztdlp.cn http://www.morning.jcfg.cn.gov.cn.jcfg.cn http://www.morning.dfqmy.cn.gov.cn.dfqmy.cn http://www.morning.gqnll.cn.gov.cn.gqnll.cn http://www.morning.njpny.cn.gov.cn.njpny.cn http://www.morning.mpnff.cn.gov.cn.mpnff.cn http://www.morning.rfzzw.com.gov.cn.rfzzw.com