String Double
1. String转Double
String a= "8.58" ;
Double b0= new Double (a);
double b1= Double . valueOf ( a) ;
double b2= Double . parseDouble ( a) ;
System . out. println ( "b0 : " + b0+ "b1 : " + b1+ " " + "b2 : " + b2) ;
2. Double 转 String
Double a = 400.40 ;
String b0 = "" + a;
String b1= String . valueOf ( a) ;
String b2 = a. toString();
String b3= String . format(“%。3f ”,a);
BigDecimal Long
1. BigDecimal 转 Long
BigDecimal b = new BigDecimal ( 12 ) ;
Long c = b. longValue ( ) ;
2. Long 转 BigDecimal
Long a = 1L ;
BigDecimal b = new BigDecimal ( a) ;
String List
1.String 转 List
import java. util. Arrays ;
List < String > list = Arrays . asList ( str. split ( "," ) ) ;
List < String > list = Arrays . asList ( StringUtils . split ( str, "," ) ) ;
List < Long > searchIds = Arrays . stream ( sList. getSearchId ( )
. substring ( 1 , sList. getSearchId ( ) . length ( ) - 1 ) . split ( "," ) )
. map ( s-> Long . parseLong ( s. trim ( ) ) ) . collect ( Collectors . toList ( ) ) ;
2. List 转 String
import cn. hutool. core. util. StrUtil ;
String str = StrUtils . join ( list, "," ) ;
String str = StringUtils . json ( list. toArray ( ) , "," ) ;
String str = String . join ( "," , list) ;
Collection 转 List
Collection < T > collection = map. values ( ) ;
List < T > list = new ArrayList < > ( collection) ;
List 转 Set
1、set转List
Set < String > set = new HashSet < String > ( ) ;
set. add ( "c" ) ;
set. add ( "d" ) ;
set. add ( "a" ) ;
set. add ( "a" ) ;
List < String > list = new ArrayList < String > ( set) ;
for ( Strings : list) {
System . out. println ( s) ;
}
System . out. println ( ) ;
List < String > list2 = new ArrayList < String > ( ) ;
list2. addAll ( set) ;
for ( Strings : list2) {
System . out. println ( s) ;
}
2、List 转 set
List < String > list = new ArrayList < String > ( ) ;
list. add ( "c" ) ;
list. add ( "d" ) ;
list. add ( "a" ) ;
list. add ( "a" ) ;
Set < String > set = new HashSet < String > ( list) ;
for ( Strings : set) {
System . out. println ( s) ;
}
System . out. println ( ) ;
Set < String > set2 = new HashSet < String > ( ) ;
set2. addAll ( list) ;
for ( Strings : set2) {
System . out. println ( s) ;
}
Object 转 map
QueryRequest queryRequest = new QueryRequest ( ) ;
TreeMap < String , String > params = JSONObject . parseObject ( JSON. toJSONString ( queryRequest) ,
new TypeReference < TreeMap < String , String > > ( ) { } ) ;
object转指定类
Object userLoginInfo = session. getAttribute ( “userLoginInfo”) ;
TfActivityLogin newUserLoginInfo= JSONObject . parseObject ( JSONObject . toJSONString ( userLoginInfo) , TfActivityLogin . class ) ;
List 转 List<对象>
List < Map < String , Object > > resultMap = dao. get ( ) ;
JSONArray jsonArray = JSONUtil . parseArray ( resultMap) ;
List < xxxVO> xxxVO = jsonArray. toList ( xxxVO. class ) ;