码迷,mamicode.com
首页 > 编程语言 > 详细

java 13-3 int类型的包装包Integer

时间:2016-09-17 21:46:51      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:


1、Integer的概述

  需求1:把100这个数据的二进制,八进制,十六进制计算出来
  需求2:判断一个数据是否是int范围内的。
       首先你得知道int的范围是多大?

   为了对基本数据类型进行更多的操作,更方便的操作,Java就针对每一种基本数据类型提供了对应的类类型。包装类类型。

        类类型     包装类类型   

          byte       Byte
        short         Short
          int           Integer
            long           Long
        float         Float
         double        Double
         char           Character
         boolean      Boolean

   用于基本数据类型与字符串之间的转换。

 1 public class IntegerDemo {
 2 public static void main(String[] args) {
 3 // 不麻烦的就来了
 4 // public static String toBinaryString(int i)
 5 System.out.println(Integer.toBinaryString(100));
 6 // public static String toOctalString(int i)
 7 System.out.println(Integer.toOctalString(100));
 8 // public static String toHexString(int i)
 9 System.out.println(Integer.toHexString(100));
10 
11 // public static final int MAX_VALUE
12 System.out.println(Integer.MAX_VALUE);
13 // public static final int MIN_VALUE
14 System.out.println(Integer.MIN_VALUE);
15 }
16 }

 


2、Integer的构造方法:
   public Integer(int value)
   public Integer(String s)
  注意:这个字符串必须是由数字字符组成

 1 public class IntegerDemo {
 2 public static void main(String[] args) {
 3 // 方式1
 4 int i = 100;
 5 Integer ii = new Integer(i);
 6 System.out.println("ii:" + ii);
 7 
 8 // 方式2
 9 String s = "100";
10 // NumberFormatException
11 // String s = "abc";
12 Integer iii = new Integer(s);
13 System.out.println("iii:" + iii);
14 }
15 }

 

java 13-3 int类型的包装包Integer

标签:

原文地址:http://www.cnblogs.com/LZL-student/p/5879687.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!