zoukankan      html  css  js  c++  java
  • java学习(第五篇)包装类

    一、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类

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

  • 相关阅读:
    (模板)高斯消元法模板
    poj1797(dijstra变形,求最小边的最大值)
    poj2253(floyd变形)
    (模板)poj2387(dijkstra+优先队列优化模板题)
    poj1915(双向bfs)
    poj3977(折半枚举+二分查找)
    uva11624 Fire! (bfs预处理)
    codeforces#1152C. Neko does Maths(最小公倍数)
    codeforces#1154F. Shovels Shop (dp)
    codeforces#1136E. Nastya Hasn't Written a Legend(二分+线段树)
  • 原文地址:https://www.cnblogs.com/wsxcode/p/11385166.html
Copyright © 2011-2022 走看看