zoukankan      html  css  js  c++  java
  • 28.5 Integer-- int的包装类

    * 由于基本数据类型只能做一些简单的操作和运算,所以Java为我们封装了基本数据类型,为每种基本数据类型提供了包装类
    * 包装类就是封装了基本数据类型的类,为我们提供了更多复杂的方法和一些变量

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

    * Integer:
    
    * 构造方法:
    * Integer(int value) int-- Integer
    * Integer(String s) String--Integer
    
    
    * String --- int
    * 方式1:
        Integer(String s) 对象的intValue()方法 *    int intValue() * * 方式2:
        static int parseInt(String s) * * * int --- String * 方式1: + "" * * 方式2:String toString() * static String toString()

      

    public class IntegerDemo {
        public static void main(String[] args) {
    
            //String --- int
            Integer i = new Integer("10");
            int a = i.intValue();
            System.out.println(a+10);
    
            int b = Integer.parseInt("5");
            System.out.println(b+12);
    
            //int --- String
            Integer i2 = new Integer(1);
            String c = i2.toString();
            System.out.println(c+21);//字符串的拼接
    
            int d = 1;
            String e = d + "";
            System.out.println(e+212);//字符串的拼接
        }
    }

    输出

  • 相关阅读:
    Oracle-函数-split 和 splitstr 的创建
    git merge方法
    查看Android 设备进程id
    内存泄漏
    Mac显示隐藏文件快捷键
    gradle版本
    commit单一文件
    21不下发信号
    FileInputStream read函数何时返回-1
    maven turbonet目录
  • 原文地址:https://www.cnblogs.com/longesang/p/11252096.html
Copyright © 2011-2022 走看看