(1)将数字转换成字符串
int i = 7;
double d = 13.56;
String str1,str2;
str1 = Integer.toString(i);
str2 = Double.toString(d);
执行以后,str1存的字符串是"7",str2存的字符串是"13.56".
(2)将字符串转换成数值
String str1 = "3532";
String str2 = "187.863";
Integer m;
Double n;
m = Integer.valueOf(str1); //将String类型转换成Integer类型
n = Integer.valueOf(str2); //将String类型转换成Double 类型
int i = m.intValue(); //将Integer类型转换成int类型
double d = n.doubleValue();
执行以后,整型变量i为3532,浮点型变量为187.863
(3)从字符串转换成数值的第2种办法
String str1 = "3532";
String str2 = "187.863";
int i = Integer.praseInt(str1);
double d = Double.praseDouble(str2);
执行以后,整型变量i为3532 ,浮点型变量d为187.863
(4)日期类型转换
//把字符串转化成日期类型
import java.sql.Date;
Date date = new Date(0);
date.valueOf("1983-09-09");
//把日期类型转换成字符串类型
import java.sql.Date;
Date date = new Date(0);
date.valueOf("1983-09-09").toString();
(5)int转成Integer
int i =0;
Integer temp = new Integer( i );
(6)String转成Integer
Integer temp = new Integer("String");
分享到:
相关推荐
`String.valueOf()` 方法和 `Integer.toString()` 方法都可以将 int 类型转换为 String 类型,而字符串连接操作符可以将 int 类型转换为 String 类型,并且可以在字符串中插入其他字符。 在实际开发中,我们通常...
通过 Integer.valueOf() 方法可以将 String 转换成 int。例如: int i = Integer.valueOf(my_str).intValue(); 2. 使用 Integer.parseInt() 方法 使用 Integer.parseInt() 方法也可以将 String 转换成 int。例如...
int i = Integer.valueOf(str).intValue();` 字符串到浮点型 将字符串转换为浮点型可以使用以下方法: * 使用 `Double.parseDouble()` 方法:`String str = "3.14"; double d = Double.parseDouble(str);` * ...
long转int 由int类型转换为long类型是向上转换,可以直接进行隐式转换,但由long类型转换为int类型是向下转换,可能会出现数据溢出情况: 主要以下几种转换方法,供参考: 一、强制类型转换 [java] long ll = ...
该资源主要介绍了android数组资源string-array integer-array的用法 包括int类型、string类型、文件类型的使用
首先给大家分享一篇 ...后来,才知道,原来js中String转int和Java中不一样,不能直接把Java中的用到js中。改成var j = parseInt(“11”);就ok了。 备注:无论是 Java 还是 JavaScript, parseInt 方法都有两
int 和 Integer 都可以表示某一个数值,但是它们不能互用,因为它们是不同的数据类型。例如: int n = 40; Integer nI = new Integer(n); ArrayList al = new ArrayList(); al.add(n); // 不可以,因为 int 不能...
第一种,使用 Integer.valueOf(),它将返回一个包装器类型 Integer,当然可以通过自动拆箱的方式将其转成 int 类型。
Java 中颜色的 String 和 Color 对象之间...Java 中颜色的 String 和 Color 对象之间的互相转换可以通过使用 `Integer.parseInt` 方法和 `Integer.toHexString` 方法实现,或者使用反射机制来实现更多的颜色表示形式。
java中数据类型转换 收藏 java中数据类型转换 ...i = Integer.parseInt([String],[int radix]); 2). int i = Integer.valueOf(my_str).intValue(); 注: 字串转成 Double, Float, Long 的方法大同小异.
String hex = Integer.toHexString(b[i] & 0xFF); if (hex.length() == 1) { hex = '0' + hex; } System.out.print(hex.toUpperCase() + " "); } System.out.println(""); } ``` 将 byte 数组转换为 16 进制...
String integer=new Long((long)theInt).toString(); String decimal=""+Math.round(theDecimal*100); if(decimal.equals("0")){ result=ChangeRMB.praseUpcaseRMB(integer); }else{ result=ChangeRMB...
在switch(expr1)中,expr1只能是一个整数表达式或者枚举常量(更大字体),整数表达式可以是int基本类型或Integer包装类型,由于,byte,short,char都可以隐含转换为int,所以,这些类型以及这些类型的包装类型也...
包含MD5加密,同时拥有多种方式进行byte或者byte[]与16...方式一:Integer.toHexString(int) 对应的是: Integer.parseInt(String, int)或者Integer.valueOf(String, int) 方式二:位运算(& 与 |) 方式三:算术运算
import java.io.*; public class FirstPart{ public static void main(String[] ...int f = Integer.parseInt(br.readLine()); double c=5*(f-32); c=c/9; System.out.println("Changing it to Celsius is "+c); } }
private static SortedMap<String, Integer> mapSortByKey(Map<String, Integer> unsort_map) { TreeMap<String, Integer> result = new TreeMap<String, Integer>() Object[] unsort_key = unsort_map.keySet()....
decimal 模块实现了定点和浮点算术运算符,使用的是大多数人所熟悉的模型,而不是程序员熟悉的模型,即大多数计算机硬件实现的 IEEE 浮点数运算。这篇文章主要介绍了python里的decimal类型转换,需要的朋友可以参考下
function GetDelivery(const recId: Int64): Integer;function GetInboxCount(const username: string; const password: string; const isRead: Boolean): Integer;function getMessages(const username: string; ...
integer int_filenum string named,cBuf GETFONTHEX("条码测试", "宋体", "chnstr01", 0, 50, 0, 1, 0, cBuf) //测试汉字转换是否成功// named='test.txt' int_filenum=FileOpen(named,StreamMode!,write!,Lock...
public static void main(String []args){ LinkedList<Integer> ab=new LinkedList(); for(int i=0;i;i++) ab.add(i+1); for(;;){ if(ab.size()==0)break;//结束条件 int i=1; while(i!=M){ ab.add(ab....