String to others
来源:互联网 发布:oracle数据库审计 编辑:程序博客网 时间:2024/06/10 05:14
package com.liuxiaoqing.demo;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;/** * * @author SorryNo4 * */public class StringToOthers {public static void StringTo() {/* * string与Integer Long short Float Double类型互转 */String string = "12345";// string数据化int i = Integer.parseInt(string);int i2 = Integer.valueOf(string).intValue();long l = Long.parseLong(string);long l2 = Long.valueOf(string).longValue();float f = Float.parseFloat(string);float f2 = Float.valueOf(string).floatValue();double d = Double.parseDouble(string);double d2 = Double.valueOf(string).doubleValue();short s = Short.parseShort(string);short ss = Short.valueOf(string).shortValue();// 数据字符串化(以int型为例,其它基本类似)String s1 = String.valueOf(i);String s2 = Integer.toString(i);String s3 = "" + i;/* * string和byte之间的转换 */String str = "12";byte b1 = Byte.parseByte(str);byte b2 = Byte.valueOf(str).byteValue();String str1 = String.valueOf(b1);String str2 = Byte.toString(b1);String str3 = "" + b1;/* * string和char之间的转换 */String sc = "shskacks";char[] charArray = sc.toCharArray();String valueOf = String.valueOf(charArray);/* * string和Boolean之间的转换 */boolean b = true;boolean bb = false;String bstr = "true";boolean boolean1 = Boolean.parseBoolean(bstr);boolean boolean2 = Boolean.valueOf(b).booleanValue();String valueOf2 = String.valueOf(b);String booleanString = Boolean.toString(b);String booleanString2 = "" + b;}public static void stringToDate() {/* * string和Date之间的转换 */// 创建一个时间:Sat Jun 03 00:04:48 CST 2017Date date = new Date();// 格式化时间:// yyyy年MM月dd日HH:mm:ss// yyyy-MM-ddString pattern = "yyyy-MM-dd";SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);// 时间格式化成字符串String string = dateFormat.format(date);// 符合条件的字符串转化成datetry {String source = "2017-01-20";Date newDate = dateFormat.parse(source);System.out.println(newDate);} catch (ParseException e) {e.printStackTrace();}}}
阅读全文
0 0
- String to others
- Ways to Encourage Others
- How to Persuade Others
- others
- others
- Others
- others
- Others
- To deal with RealMedia and Others
- It's a pleasure to help others
- How to undo pending changes by others
- Hard to understand what others' are saying ...
- to be ruled from Windows Space (others)
- Aptana 3 and say bye to others!
- How to check others Concurrent Request Output
- How do I invite others to join Gmail?
- How To Become Rich By Making Others Rich
- Check Your Code First before Looking to Blame Others
- ACM算法竞赛入门(第二版)题目代码==持续更新中
- Sigmoid函数
- CSU OJ 1505: 酷酷的单词
- Shell编程
- 数据类型的最大最小值
- String to others
- 小希的迷宫||HDU1272
- 集合框架——可变参数、静态导入
- Zeppelin源码分析-独立解释器 JVM 相关分析(3)
- UPC 2017 Summer Training 1
- JS中的数组
- Java多线程基础--07之 线程休眠
- 257. Binary Tree Paths
- C++内置函数(内嵌函数,内联函数)