【IntelliJ IDEA 2019.3】java各种类型转换

其他类型转String

String s = String.valueOf( value); // 其中 value 为任意一种数字类型。 

字符串型转换成各种数字类型:

String s = "169"; 


byte b = Byte.parseByte( s ); 


short t = Short.parseShort( s ); 


int i = Integer.parseInt( s ); 


long l = Long.parseLong( s ); 


Float f = Float.parseFloat( s ); 


Double d = Double.parseDouble( s );

String 转 boolean

IsRes = Boolean.parseBoolean("true")

String转byte[]格式

一般现在统一使用的UTF-8编码方式,在这种方式下,中文不会出现乱码。

例如:

String message = “你好,这是编码测试abc”;
//将其转换成”UTF-8”编码的byte格式
byte convert[] = message.getBytes( “UTF-8” );

或者

byte convert[] = message.getBytes();

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章