基本类型和字符串的转换

基本类型->字符串

  1. 使用+号
     int n1 =10;
    String a= n1 + "";
    
  2. 使用Integer类中的toString方法
    String s2 = Integer.toString(n1);
    
  3. 转换的时候改变进制
    String s3 = Integer.toString(n1,16) // 重载方法
    

字符串转换->基本类型

  1. 使用Integer.parseXXX()
String str = "150";
int n2 = Integer.parseInt(n2);

boolean字符串形式转成基本类型 "true"-> true 非"true"-> false

用Boolean.parseBoolean();


本文章使用limfx的vscode插件快速发布