【IntelliJ IDEA 2019.3】java各种类型转换
其他类型转String
String s = String.valueOf( value); // 其中 value 为任意一种数字类型。
其他类型转int
String COMx = "3";
int i = Integer.valueOf(COMx);
字符串型转换成各种数字类型:
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();
char 转 Byte
byte b = (byte)c;
决不能写成 Byte b = (Byte)c; 不能大写。
List<Byte> 转 byte[]
byte[] ret = new byte[ValidData.size()];
for (int i=0; i<ValidData.size(); i++){
ret[i] = ValidData.get(i);
}
浙公网安备 33010602011771号