android int 和 String 互相转换的多种方法

samool 发布暂无评论17232 阅读

AI摘要

文章介绍了在Android开发中,如何将字符串(String)和整数(int)互相转换的多种方法。对于将字符串转换为整数,可以使用Integer.parseInt()或Integer.valueOf()方法。对于将整数转换为字符串,可以使用String.valueOf()、Integer.toString()或直接使用字符串连接操作符。这些方法同样适用于其他数值类型,如Double、Float和Long。

1 如何将字串 String 转换成整数 int? 

A. 有两个方法:

1). int i = Integer.parseInt([String]); 或 
i = Integer.parseInt([String],[int radix]);

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

注: 字串转成 Double, Float, Long 的方法大同小异. 

2 如何将整数 int 转换成字串 String ? 

A. 有叁种方法:

1.) String s = String.valueOf(i);

2.) String s = Integer.toString(i); 

3.) String s = "" + i; 

注: Double, Float, Long 转成字串的方法大同小异. 

  1. 01自建php仿新浪短网址服务2020-11-18
  2. 02Golang 汇编入门知识总结2020-09-27
  3. 03android平台获取手机IMSI、IMEI 、序列号和手机号的方法2016-01-07
  4. 04Android TextView添加滚动条2014-05-09
  5. 05Android TextView换行问题2014-03-25
  6. 06android 删除文件2013-07-26
  7. 07android bitmap的放大缩小2013-07-26
  8. 08Android MediaPlayer使用方法2013-02-16
  9. 09Android软件图标的几种大小2013-01-07
  10. 10谷歌发布Android 4.2系统2012-10-30
COMMENTS / 一纸留言

读者留言 0 条

一纸留言,便是山水间的一次相逢。

还没有留言,欢迎写下第一段交流。

WRITE A COMMENT

写下你的留言