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类

  • 相关阅读:
    Spring(二) Spring装配Bean的几种方式
    Spring(一) Spring配置文件中classpath和classpath*的区别
    学习响应式编程 Reactor (5)
    学习响应式编程 Reactor (4)
    学习响应式编程 Reactor (3)
    学习响应式编程 Reactor (2)
    学习响应式编程 Reactor (1)
    学习Java 8 Stream Api (5)
    学习Java 8 Stream Api (4)
    Spring WebFlux 学习笔记
  • 原文地址:https://www.cnblogs.com/lgxstudy/p/4449048.html
Copyright © 2011-2022 走看看