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类

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

  • 相关阅读:
    LAMP搭建示例
    MySQL主从
    list多字段去重
    mysql按照某一个条件进行分组统计,同时又要保证一个相同字段的数据只统计一次
    sentinel自定义异常处理
    sentinel规则持久化
    zookeeper
    shiro
    iframe之间传递参数
    自定义标签
  • 原文地址:https://www.cnblogs.com/wsxcode/p/11385166.html
Copyright © 2011-2022 走看看