其他類型轉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();