1、如何将字符串String转化为整数int
int i = Integer.valueOf(my_str).intValue();
注: 字串转成Double, Float, Long的方法大同小异。
2、如何将字符串String转化为Integer
答:有三种方法:
String s = String.valueOf(i);
String s = Integer.toString(i);
String s = "" + i;
注:Double, Float, Long 转成字串的方法大同小异。
JAVA中long,float,int类型与String类型的相互转换: 收藏
<script type="text/javascript"> document.body.oncopy = function() { if (window.clipboardData) { setTimeout(function() { var text = clipboardData.getData("text"); if (text && text.length > 300) { text = text + "/r/n/n本文来自CSDN博客,转载请标明出处:" + location.href; clipboardData.setData("text", text); } }, 100); } } </script>1 、将字符串Stirng 转换成整形Int ,Float ,Double ,Long 的方法大同小异:有两种方法:
Ø int i = Integer.parseInt([String])
Ø int i = IntegervalueOf(my_str).intValue();
2 、将整形 Int , Float , Double , Long 转换成 String 的方法也大 同小异:有三种方法:
Ø String s = StringvalueOf(i);
Ø String s = Integer.toString(i);
Ø String s = “”+i;
3 、将字符串 String 转换成 Date 型有一种方 法:
Ø 首先要包含 import java.text.*; ,然后定义 DateFormat format = new SimpleDateFormat(“yyyy-MM-dd”) 或者 DateFormat format = new SimpleDateFormat(“yyyy 年 MM 月 dd 日 HH 时 mm 分 ss 秒 ”) 等。最后 Date date = format.parse(str);
4 、将 Date 型转换成 String 类型有一种方法:
Ø 首先要包含 import java.text.*; ,然后定 义 DateFormat format = new SimpleDateFormat(“yyyy-MM-dd”) 或
者 DateFormat format = new SimpleDateFormat(“yyyy 年 MM 月 dd 日 HH 时 mm 分 ss 秒 ”) 等。最后 str =
format.format(date)