当前位置:网站首页>Packaging_ Conversion between basic type and string type

Packaging_ Conversion between basic type and string type

2022-06-24 20:57:00 Platonic

 Basic types --> character string 
  1. Value of basic type data +"" The easiest way ( Often used in work )
  2. Use static methods in the wrapper class 
*   static string tostring(int i) : Returns a... That represents a specified integer string object 
* 3. Use string Static methods in a class 
      static string valueof(int i) : return int String representation of parameter 

   character string --> Basic types 
     Use static methods of wrapper classes parseXX(" character string 0");
    Integer class :static int parseInt(String s)
    Double class :static double parseDouble(String s)

 Just code examples :
public class Demo03Integer {
    public static void main(String[] args) {
        // Basic types --> character string 
        String s1=100+"";
        System.out.println(s1+200);

        String s = Integer.toString(10);
        System.out.println(s+200);
        String integer = String.valueOf(200);
        System.out.println(integer+200);

        // character string --> Basic types 
        int i = Integer.parseInt("1");
        System.out.println(i+200);

    }
}
100200
10200
200200
201

Results, :

原网站

版权声明
本文为[Platonic]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211325382546.html