数据类型转换(groovy)


int类型--------->String类型

方式一:

int num = 100;
String s = "" + num;
方式二:

int num = 100;
String s = String.valueOf(num);
//String类下valueOf可将任何类型转换成String类型
方式三:
int num=100;
Integer in = new Integer(num);
String s= in.toString();
方式四:
int num=100;
String s = Integer.toString(num);


String类型--------->int类型

方式一:

String s = "100";
Integer in= new Integer(s);
//Integer类下将Integer转换成功int的方法
int num = in.intValue();
方式二:
String s=“100”;
int num = Integer.parseInt(s);
--------------------- 
作者:Ditanse 
来源:CSDN 
原文:https://blog.csdn.net/nocol123/article/details/71513182 
版权声明:本文为博主原创文章,转载请附上博文链接!

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM