zoukankan      html  css  js  c++  java
  • java中常用的类型转换

    1.将字符串转换成整数(String--->int)
    方法一:
      (1)  int i = Integer.parseInt(String s); 

       其中(1)其实就是我们经常用到的将s转换为10进制得数,其实默认是调用了 int i =Integer.parseInt("123",10);     

     (2)  i = Integer.parseInt(String s,int radix);

         radix的范围是在2~36之间,超出范围会抛异常。其中s的长度也不能超出7,否则也会抛异常。

    方法二: 

      int i = Integer.valueOf(my_str).intValue();

      注: 字串转成 Double, Float, Long 的方法与上面类似.

    2.如何将整数 转换成字串(int--->String) 

      (1) String s = String.valueOf(i);
      (2) String s = Integer.toString(i);
      (3) String s = "" + i;
      注: Double, Float, Long 转成字串的方法与上面类似.

  • 相关阅读:
    HDU-1527 取石子游戏
    HDU-1846 Brave Game
    HDU-1850 Being a Good Boy in Spring Festival
    HDU-2509 Be the Winner
    HDU-1907 John
    HDU-1969 Pie
    HDU-1501 Zipper
    HDU-2289 Cup
    最大子矩阵和
    HDU3466(01背包变种)
  • 原文地址:https://www.cnblogs.com/changjl/p/4174742.html
Copyright © 2011-2022 走看看