String与Int类型的转换
http://blog.sina.com.cn/s/blog_4f9d6b1001000bfo.html
int -> String
int i=12345;
String s="";
第一种方法:s=i+"";
第二种方法:s=String.valueOf(i);
这两种方法有什么区别呢?作用是不是一样的呢?是不是在任何下都能互换呢?
String -> int
s="12345";
int i;
第一种方法:i=Integer.parseInt(s);
第二种方法:i=Integer.valueOf(s).intValue();
这两种方法有什么区别呢?作用是不是一样的呢?是不是在任何下都能互换呢?
以下是答案:
|
第一种方法:s=i+""; 第一种方法:i=Integer.parseInt(s);//直接使用静态方法,不会产生多余的对象,但会抛出异常 第二种方法:i=Integer.valueOf(s).intValue();//Integer.valueOf(s) |
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 的方法大同小异.
?
1.) String s = String.valueOf(i);
2.) String s = Integer.toString(i);
3.) String s = "" + i;
注: Double, Float, Long 转成字串的方法大同小异.
JAVA数据类型转换
这是一个例子,说的是JAVA中数据数型的转换.供大家学习
package shenmixiaozhu;
import java.sql.Date;
public class TypeChange {
public TypeChange() {
}
//change the string type to
the int type
public
static int stringToInt(String
intstr)
{
Integer integer;
integer = Integer.valueOf(intstr);
return integer.intValue();
}
//change int type to the
string type
public static String
intToString(int value)
{
Integer integer = new Integer(value);
return integer.toString();
}
//change the string type to
the float type
public
static float
stringToFloat(String floatstr)
{
Float floatee;
floatee = Float.valueOf(floatstr);
return floatee.floatValue();
}
//change the float type to the
string type
public static String
floatToString(float value)
{
Float floatee = new Float(value);
return floatee.toString();
}
//change the string type to
the sqlDate type
public static java.sql.Date
stringToDate(String dateStr)
{
return
java.sql.Date.valueOf(dateStr);
}
//change the sqlDate type to
the string type
public static String
dateToString(java.sql.Date datee)
{
return datee.toString();
}
public static void
main(String[] args)
{
java.sql.Date day ;
day = TypeChange.stringToDate("2003-11-3");
String strday = TypeChange.dateToString(day);
System.out.println(strday);
}
虽然都能在JAVA API中找到,整理一下做个备份。
String与Int类型的转换的更多相关文章
- 03.枚举和string以及int类型之间的转换
练习1: 将枚举类型强转成int类型 namespace _04.枚举类型的练习01 { //声明一个QQState类型的枚举 public enum QQState { OnLine, OffL ...
- java和python中的string和int数据类型的转换
未经允许,禁止转载!!! 在平时写代码的时候经常会用到string和int数据类型的转换 由于java和python在string和int数据类型转换的时候是不一样的 下面总结了java和python ...
- 【转】java中byte数组与int类型的转换(两种方式)----不错
原文网址:http://blog.csdn.net/piaojun_pj/article/details/5903009 java中byte数组与int类型的转换,在网络编程中这个算法是最基本的算法, ...
- C# enum、int、string三种类型互相转换
enum.int.string三种类型之间的互转 #代码: public enum Sex { Man=, Woman= } public static void enumConvert() { in ...
- 总结:String类型与Int类型的转换【实现插入操作主键自增】
1.String类型(此类型是数字格式的字符串类型)转换成Int类型 String str = "10000"; 转换成Int类型: int num = Integer.parse ...
- java 13-4 Integer和String、int之间的转换,进制转换
1.int类型和String类型的相互转换 A.int -- String 推荐用: public static String valueOf(int i) 返回 int 参数的字符串表示形式. B. ...
- String与其他类型的转换
首先,对于String类有一点是毫无疑问的:对String对象的任何改变都不影响到原对象,相关的任何change操作都会生成新的对象. 一. String与StringBuilder.StringBu ...
- C++ 中 string, char*, int 类型的相互转换
一.int 1.int 转换成 string 1) to_string函数 —— c++11标准增加了全局函数std::to_string: string to_string (int val); s ...
- String,Integer,int类型之间的相互转换
String, Integer, int 三种类型之间可以两两进行转换 1. 基本数据类型到包装数据类型的转换 int -> Integer (两种方法) Integer it1 = new I ...
随机推荐
- 高性能内存图数据库RedisGraph(三)
这篇文章,我将介绍截止目前,RedisGraph的最新版本(v2.4)对Cypher语言的支持情况. 1.模式(patterns) RedisGraph已支持Cypher中所有的模式. 2.类型(ty ...
- mybatis的增删改查返回值小析(六)
本文验证了通过mybatis访问数据库时的,增删改查的返回值情况. 直接看代码. 1.service层 /** *@Author: Administrator on 2020/3/12 15:15 * ...
- PHP-CGI远程代码执行漏洞(CVE-2012-1823)
影响版本 php < 5.3.12 or php < 5.4.2 访问http://p:8080/index.php?-s即爆出源码,说明漏洞存在 POST /index.php?-d+a ...
- Pdb— Python的调试器
参考:Pdb- Python的调试器 pdb 模块定义了一个交互式源代码调试器,用于 Python 程序.它支持在源码行间设置(有条件的)断点和单步执行,检视堆栈帧,列出源码列表,以及在任何堆栈帧的上 ...
- 大数据学习(03)——HDFS的高可用
高可用架构图 先上一张搜索来的图. 如上图,HDFS的高可用其实就是NameNode的高可用. 上一篇里,SecondaryNameNode是NameNode单节点部署才会有的角色,它只帮助NameN ...
- 异地远程访问群晖NAS中的文件
异地远程访问群晖NAS中的文件 我以群晖DS720+网络存储服务器为例,介绍我是如何异地远程访问群晖NAS中的文件的. 此文章只介绍部署操作的大概步骤,具体的操作方法和技巧可以在西瓜视频.抖音 ...
- 一键设置WPS_Office_2019专业版的定时自动备份的批处理文件
一键设置WPS_Office_2019专业版的定时自动备份的批处理文件 rem ================================================ rem 一键设置WPS ...
- Windows协议 LDAP篇 - 组&OU
LDAP搜索 LDAP查找 位操作 以userAccountControl为例,CN=User-Account-Control,CN=Schema,CN=Configuration,DC=muxue, ...
- k8s之Service详解-Service使用
实验环境准备 在使用service之前,首先利用deployment创建出3个pod,注意要为pod设置app=nginx-pod的标签 创建deployment.yaml,内容如下 apiVersi ...
- 跟我一起写 Makefile(二)
三.make是如何工作的 在默认的方式下,也就是我们只输入make命令.那么, 1.make会在当前目录下找名字叫"Makefile"或"makefile"的文 ...