zoukankan      html  css  js  c++  java
  • 包装类

    基本数据类型为int,short ,byte,char,long,double,boolean

    基本数据类型的包装类Integer,Short,Byte,Character,Long,Double,Boolean

    第一种构造方法把基本类型包装为包装类

    public Type(type value)

    创建一个包装类对象例子:

    Integer intValue=new Integer(21);
    Long longValue=new Long(21L);
    Character charValue=new Character('x');
    Boolean booleanValue=new Boolean(true);
    Float floatValue=new Float(21F);

    第二种构造方法把字符串转换为包装类

    Byte byteValue=new Byte("21");
    Float floatValue=new Float("21");
    Short shorValue=new Short("11"); Integer intValue=new Integer("22");
    Double doubleValue=new Double("22.2");
    Boolean booleanValue=new Boolean("true");

    Character不能使用第二种构造方法,因为他不能接收字符串。

    包装类转基本类型

    public type typeValue();

    Integer a=new Integer(10);
    int a1=a.intValue();
    Long a2=new Long(11);
    long a3=a2.longValue();
     其他类型也是xxxValue();除了Character

    在Character类中有两个静态方法
    publice static boolean isDigit(char ch)确定制定字符串是否为数字。

    public static boolean isLetter(char ch)确定制定字符是否为字母。

     字符串转基本类型

    public static tpe paseType(String type);

    int num=Integer.parseInt("36");
    long longValue=Long.parseLong("2623");

    基本类型转字符串
    public static String toString(type value);

    String sex=Character.toString('');
    String id =Integer.toString(26);
    String sex=''+"";
    String id=25+"";

     Math类

  • 相关阅读:
    php+apache+mysql环境搭建
    怎么理解依赖注入
    maven修改远程和本地仓库地址
    idea创建的java web项目打包发布到tomcat
    MYSQL 导入导出数据库文件
    MySQL约束
    mysql字符集校对
    prime
    POJ-2564 01背包问题
    POJ-1564 dfs
  • 原文地址:https://www.cnblogs.com/lgxstudy/p/4449048.html
Copyright © 2011-2022 走看看