zoukankan      html  css  js  c++  java
  • Java int类型与String类型互转

    String类型转换为int类型

    参考:https://blog.csdn.net/qq_35995940/article/details/78433404?locationNum=5&fps=1

    例:

     1 public class StringToInt {
     2     public static void main(String[] args) {
     3         String str = "1313";
     4         int i = 0;
     5         
     6         // eg 1
     7 //        try {
     8 //            i = Integer.parseInt(str);
     9 //        } catch (NumberFormatException e) {
    10 //            e.printStackTrace();
    11 //        }
    12         
    13         // eg 2
    14         try {
    15             i = Integer.valueOf(str).intValue();
    16         } catch (NumberFormatException e) {
    17             e.printStackTrace();
    18         }
    19         
    20         i += 1;
    21         System.out.println(i);
    22     }
    23 }

      

    int类型转换为String类型

    例:

     1 public class intToString {
     2     public static void main(String[] args) {
     3         int i = 1314;
     4         
     5         // eg 1
     6 //        String str = String.valueOf(i);
     7         
     8         // eg 2
     9 //        String str = Integer.toString(i);
    10         
    11         // eg 3
    12         String str = "" + i;
    13         
    14         System.out.println(str);
    15     }
    16 }
  • 相关阅读:
    spring boot(二)web综合开发
    spring boot(一)入门
    shiro中单点登录
    shiro中SSL
    shiro中记住我功能
    spring中集成shiro
    OpenResty
    源代码安全审计
    Mycat读写分离 + 主从复制(Gtid)
    关于ansbile
  • 原文地址:https://www.cnblogs.com/Satu/p/9877105.html
Copyright © 2011-2022 走看看