码迷,mamicode.com
首页 > 编程语言 > 详细

java学习(第五篇)包装类

时间:2019-08-20 20:32:38      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:返回   判断   pac   ant   oid   ted   main   class   不为   

一、Integer

package com.test01;

public class IntegerTest01 {

public static void main(String[] args) {
// TODO Auto-generated method stub
Integer a=new Integer(1); //integer类在对象在包装了一个基本类型int的值
//上面为一种构造方法:以一个int型变量作为参数创建一个integer对象
Integer s=new Integer("1");
//上面为一种构造方法:以一个string型变量作为参数创建一个integer对象
Integer b=new Integer(1);
int c=a.compareTo(b);//compareTo()方法:比较两个integer对象,相等返回0,a<b返回负数,a>b返回正数
System.out.println(c);
System.out.println(a.equals(b));
System.out.println(a.toString());//toString()方法:将int型转为字符型
int d=Integer.parseInt("123");//parseInt(string):返回int值,将字符串(纯数值型)转变为int型
System.out.println(d);

}

}

二、Boolean

package com.test01;

public class BooleanTest01 {

public static void main(String[] args) {
// TODO Auto-generated method stub
Boolean a=new Boolean(true);

Boolean b=new Boolean("abc");
//如果string参数不为空,分配一个true的布尔对象

}

}

三、Byte

package com.test01;

public class ByteTest01 {

public static void main(String[] args) {
// TODO Auto-generated method stub
byte abyte=45;
Byte a=new Byte(abyte);

Byte bbyte=new Byte("123");


}

}

四、Character

package com.test01;

public class CharacterTest01 {
public static void main(String args[])
{
char c=‘a‘;
Character a=new Character(c);
System.out.println(Character.toUpperCase(‘b‘));
//将字符型变量转为大写
System.out.println(Character.toLowerCase(‘c‘));
//转为小写
System.out.println(Character.isUpperCase(c));
//判断是否为大写
System.out.println(Character.isLowerCase(c));
//判断是否为小写
}
}

五、number类

是以上所有类的父类,是抽象类

java学习(第五篇)包装类

标签:返回   判断   pac   ant   oid   ted   main   class   不为   

原文地址:https://www.cnblogs.com/wsxcode/p/11385166.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!