包装类:将 基本数据类型 封装成 对象 的好处在于可以在 对象 中定义更多的 功能方法 操作该数据
常用的操作之一:将 基本数据类型 与 字符串 之间进行转换
基本数据类型 与 包装类 的对应:
byte Byte short Short int Integer long Long float Float double Double char Character boolean Boolean
int 转换为 String
Integer 常用方法:
toString() 将Integer转换为String
intValue() 将Integer转换为int
parseInt() 将String转换为int
基本数据类型包装类有8种,其中7种都有 parseXxx() 方法,将这7种字符串表现形式转换为基本数据类型
其中char 的包装类 Character 中没有 parseXxx方法。字符串到字符的转换通过 toCharArray() 可以把字符串转换为字符数组
常见面试题:
原文:https://www.cnblogs.com/gaoyang666/p/11141313.html