码迷,mamicode.com
首页 > 编程语言 > 详细

Java类型转换.

时间:2019-06-20 21:16:48      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:big   type   tom   name   dcl   tree   asList   addclass   val   

Object->Map

Array->List

String[] atp = {"Rafael Nadal", "Novak Djokovic",
                "Stanislas Wawrinka",
                "David Ferrer", "Roger Federer",
                "Andy Murray", "Tomas Berdych",
                "Juan Martin Del Potro"};
List<String> players = Arrays.asList(atp);

->Array

Collection.toArray() 
/*ArrayList ,EnumSet , HashSet ,LinkedHashSet , LinkedList , Stack , TreeSet , Vector */

->String

String.copyValueOf(charArray) #Array->String

技术图片

Date -> String

//如果希望得到YYYYMMDD的格式
SimpleDateFormat sy1=new SimpleDateFormat("yyyyMMDD");
String dateFormat=sy1.format(date);

//如果希望分开得到年,月,日
SimpleDateFormat sy=new SimpleDateFormat("yyyy");
SimpleDateFormat sm=new SimpleDateFormat("MM");
SimpleDateFormat sd=new SimpleDateFormat("dd");
String syear=sy.format(date);
String smon=sm.format(date);
String sday=sd.format(date);

//String -> Date
String reportdate_str ="2005-10-01";
reportdate_str = reportdate_str + "00:00:00.0";
Date reportdate = java.sql.Timestamp.valueOf(reportdate_str);

->int、double、other

//int
Integer.parseInt(String s)
int i = Double.intValue();
Character.getNumericValue('a');

//double
(new Float(100.00f)).doubleValue();
Double.valueOf("32.1").doubleValue();
Double d = Double.parseDouble( s );

//other
byte b = Byte.parseByte( s );
short t = Short.parseShort( s );
long l = Long.parseLong( s );
Float f = Float.parseFloat( s );

技术图片
技术图片

时间->String

V_DATE = reportdate.toString();

工具类

com.alibaba.fastjson.util.TypeUtils

Method Summary
static void addBaseClassMappings()

static void addClassMapping(String className, Class<?> clazz)

static
T cast(Object obj, Class clazz, ParserConfig mapping)

static
T cast(Object obj, ParameterizedType type, ParserConfig mapping)

static
T cast(Object obj, Type type, ParserConfig mapping)

static BigDecimal castToBigDecimal(Object value)

static BigInteger castToBigInteger(Object value)

static Boolean castToBoolean(Object value)

static Byte castToByte(Object value)

static byte[] castToBytes(Object value)

static Character castToChar(Object value)

static Date castToDate(Object value)

static Double castToDouble(Object value)

static
T castToEnum(Object obj, Class clazz, ParserConfig mapping)

static Float castToFloat(Object value)

static Integer castToInt(Object value)

static
T castToJavaBean(Map<String,Object> map, Class clazz, ParserConfig mapping)

static
T castToJavaBean(Object obj, Class clazz)

static Long castToLong(Object value)

static Short castToShort(Object value)

static Date castToSqlDate(Object value)

static String castToString(Object value)

static Timestamp castToTimestamp(Object value)

static void clearClassMapping()

static List computeGetters(Class<?> clazz, Map<String,String> aliasMap)

static List computeGetters(Class<?> clazz, Map<String,String> aliasMap, boolean sorted)

static Class<?> getClass(Type type)

static Class<?> loadClass(String className)

.

Java类型转换.

标签:big   type   tom   name   dcl   tree   asList   addclass   val   

原文地址:https://www.cnblogs.com/liehen2046/p/11061358.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!