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