Java数据类型中String、Integer、int相互间的转换
1.Integer转换成int的方法
Integer i;
int k = i.intValue();
即Integer.intValue();
2.int转换成Integer
int i;
Integer it = new Integer(i);
3.String转换成int的方法
String str = "10";
Integer it = new Interger(str);
int i = it.intValue();
即:int i = Integer.intValue(string);
4.int转换成String
int i;
(1)String s = String.valueOf(i);
(2)String s = Ingeger.toString(i);
(3)String s = "" + i;
5.String转换成Integer
String str = "10"
Integer it = Integer.valueOf(str);
6.Integer转换成String
Integer it;
String str = it.toString();
7.String转换成BigDecimal
BigDecimal bd = new BigDecimal(str);
8.日期
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH)+1;
int day = calendar.get(Calendar.DATE);
//获取今天的日期字符串
String today = java.text.DateFormat.getDateInstance().format(new java.util.Date());
//获取今天的日期
new java.sql.Date(System.currentTimeMillis());
Java数据类型中String、Integer、int相互间的转换的更多相关文章
- (备忘)Java数据类型中String、Integer、int相互间的转换
1.Integer转换成int的方法 Integer i; int k = i.intValue();即Integer.intValue(); 2.int转换成Integer int i; Integ ...
- Java中String转int型的方法以及错误处理
应要求,本周制作了一个判断一个年份是否是闰年的程序.逻辑很简单,这里就不贴代码了.可是,在这次程序编写中发现了一个问题. 在输入年份时,如果输入1)字母2)空3)超过Int上限时,就会抛excepti ...
- Java学习之String与int的相互转换
•String 转 int 两种方式 int a = Integer.parseInt(s);int b = Integer.valueOf(s).intValue(); 代码 public clas ...
- String,Integer,int类型之间的相互转换
String, Integer, int 三种类型之间可以两两进行转换 1. 基本数据类型到包装数据类型的转换 int -> Integer (两种方法) Integer it1 = new I ...
- Linq中string转int的方法
Linq中string转int的方法 在做批量删除时,需把一串id值所对应的数据删除,调试出现问题: Linq语句中如果使用ToString()进行类型转换,编译时不会报错,但执行时会出现如下错误 ...
- Js中String转int
Js中String转int 方案一代码: Number(str) 方案二代码: //parseInt 方法都有两个参数, 第一个参数就是要转换的对象, 第二个参数是进制基数, 可以是 2, 8, 10 ...
- java基本数据类型及相互间的转换
1.首先复习一下java的基本数据类型,见下图 2.比较他们的字节数 备注:1字节(Byte)=8位(Bit) 3.转换中的知识点 *java中整数类型默认的int类型:小数类型默认的double: ...
- java中string和int互相转化
1 怎样将字串 String 转换成整数 int? A. 有两个方法: 1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt([ ...
- Java中List, Integer[], int[]的相互转换
import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; public class Mai ...
随机推荐
- C/C++ 跨平台交叉编译、静态库/动态库编译、MinGW、Cygwin、CodeBlocks使用原理及链接参数选项
目录 . 引言 . 交叉编译 . Cygwin简介 . 静态库编译及使用 . 动态库编译及使用 . MinGW简介 . CodeBlocks简介 0. 引言 UNIX是一个注册商标,是要满足一大堆条件 ...
- javascript显示实时时间
<html> <script language=Javascript> function time(){ //获得显示时间的div t_div = document.getEl ...
- MySQL里面的子查询实例
一,子选择基本用法 1,子选择的定义 子迭择允许把一个查询嵌套在另一个查询当中.比如说:一个考试记分项目把考试事件分为考试(T)和测验(Q)两种情形.下面这个查询就能只找出学生们的考试成绩 selec ...
- 修改myeclipse 新建JSP文件时的默认模板
MyEclipse中构造新的jsp模板(原创) 首先随便打开一个jsp页,在网页中单击右键选择:preferences 打开后如图所示,找到jsp template选项. 选择new,在弹出的提示框, ...
- MyEclipse------随机流(能读也能写数据)
RandomAccessFile流指向文件时,不刷新文件. 其中seek(long a)用来定位RandomAccessFile流的读写位置,其中参数a确定读写位置距离文件开头的字节个数. other ...
- 面向对象之集合ArrayList
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using S ...
- webshell提权20种思路
1,SER-TU提权(通常是利用SERFTP服务器管理工具,首先要在安装目录下找到INI配置文件,必须具备可写入的权限)2,RADMIN提权(大家并不陌生,我们在扫描4899空口令后,同样需要他来连接 ...
- Kali实现局域网ARP欺骗和ARP攻击
原文地址: http://netsecurity.51cto.com/art/201303/386031.htm http://xiao106347.blog.163.com/blog/static/ ...
- Js日期选择器并自动加入到输入框中
<html> <head> <title>Js日期选择器并自动加入到输入框中</title> <meta http-equiv="con ...
- swift中文文档- 类型转换
未翻译完 待续(英语烂,求斧正) Type Casting 类型转换 Type casting is a way to check the type of an instance, and/or to ...