黑马程序员技术交流社区

标题: 包装类 [打印本页]

作者: 左冬至1111111    时间: 2016-9-4 21:55
标题: 包装类

包装类:
                作用:可以让基本类型的数据调用方法了。
                基本类型:                包装类:
                byte                        Byte
                short                        Short        
                char                        Character
                int                                Integer
                long                        Long
                float                        Float
                double                        Double
                boolean                        Boolean

                包装类和String类型之间的相互转换:
                        String --》 Integer
                                方式1:                //掌握
                                        int num = Integer.parseInt("123");        //把String类型转成对应的int类型的值。
                                方式2:
                                        Integer i = new Integer("123");
                                        int num = i.intValue();

                        Integer --》 String
                                方式1:                //掌握
                                        String str = 10 + "";
                                方式2:
                                        String str = Integer.toString(10);
                                方式3:
                                        String str = String.valueOf(10);

                        Integer 类中的其他方法:
                                public static String toBinaryString();
                                public static String toOctalString();
                                public static String toHexString();




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2