首页 > 其他 > 详细

包装类

时间:2022-05-27 20:51:34      阅读:15      评论:0      收藏:0      [点我收藏+]
package com.liu.demo0;

public class Int1 {
public static void main(String[] args) {
//基本类型和字符串之间的转换
int n = 255;
//基本类型转成字符串
//1.使用+号
String s1 = n+"";
//2.使用Integer中的toString()方法
String s2 =Integer.toString(n);
String s3 =Integer.toString(n,16);//后面代表用几进制表示
System.out.println(s3);

//字符串转成基本类型
String str = "150";
//使用Integer.parseXXX();// Integer是包装类 xxx代表基本类型 转那个类型换那个
//Double.parseDouble(str);
int n2 = Integer.parseInt(str);

//boolean 字符串形式转成基本类型 true为true 其余都为false;
String str2 = "true";
String str3 = "false";
String str4 = "f";
boolean b1 =Boolean.parseBoolean(str2);
boolean b2 =Boolean.parseBoolean(str3);
boolean b3 =Boolean.parseBoolean(str4);
System.out.println(b1);
System.out.println(b2);
System.out.println(b3);

}
}

包装类

原文:https://www.cnblogs.com/sm12580/p/15335166.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!