• 8.包装类常用方法


    /**
     * 包装类常用方法
     * */
    public class Demo {
        public static  void main(String[] args){
            //XXXValue():包装类转换成基本类型
            Integer integerId=new Integer(25);
            int intId=integerId.intValue();
            System.out.println(intId);
            
            Boolean booleanVal=new Boolean(true);
            boolean bool2=booleanVal.booleanValue();
            System.out.println(bool2);
            System.out.println("*************************");
            
            //toString():以字符串形式返回包装对象表示的基本类型数据
            String sex=Character.toString('男');
            String id=Integer.toString(89);
            System.out.println(sex);
            System.out.println(id);
            String sex2='男'+"";
            String id2=89+"";
            System.out.println(sex2);
            System.out.println(id2);
            System.out.println("*************************");
            
            //所有包装类valueOf(type value)
            Integer intValue=Integer.valueOf(21);
            System.out.println(intValue);
            Boolean bool=Boolean.valueOf(false);
            System.out.println(bool);
            System.out.println("*************************");
            
            //除Character类外,其他包装类valueOf(String s)
            intValue=Integer.valueOf("32");
            //bool=Boolean.valueOf("true");
            bool=Boolean.valueOf("love");
            //编译错误
            //Character c=Character.valueOf("a");
            System.out.println(intValue);
            System.out.println(bool);
            System.out.println("*************************");
            
            //parseXXX():把字符串转换为相应的基本数据类型数据(Character除外)
            int i=Integer.parseInt("89");
            System.out.println(i);
            //boolean flag=Boolean.parseBoolean("true");
            //boolean flag=Boolean.parseBoolean("TRue");
            //boolean flag=Boolean.parseBoolean("love");
            boolean flag=Boolean.parseBoolean("false");
            System.out.println(flag);
            System.out.println("*************************");
            
            //基本类型和包装类的自动转换:装箱和拆箱
            //装箱
            Integer intObject=5;
            //拆箱
            int intValue2=intObject;
            System.out.println(intObject+"	"+intValue2);
        }
    }
  • 相关阅读:
    8月30日图雄网站隆重推出三维地图服务系统!!!
    电子地图真的是百花齐放了——百度地图即将发布
    GIS应对新挑战——空间信息网格技术探寻
    C盘和其他盘中间有恢复分区,C盘无法扩展的解决办法之一
    osg绘制ifc工字钢的端面
    protobuf编译
    osg绘图的形式
    colors
    SpeechSynthesisUtterance
    kinova jaco2 控制机械臂动作
  • 原文地址:https://www.cnblogs.com/xiaotaoxu/p/5536628.html
Copyright © 2020-2023  润新知