1.字符串、日期之间的转换
1.1字符串转日期类型
格式化:SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd")
转换:Date date= sdf.parse(字符串类型)
String str = "2022-07-09";
Date parse = new SimpleDateFormat("yyyy-MM-dd").parse(str);
1.2日期类型准换为字符串类型
sdf.format(日期类型):将日期类新房的数据转换为字符串类型。
1.3将日期格式化为:yyyy-MM-dd格式
1.准备Date类型的数据
2.创建SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
3.simpleDateFormat.Format(Date类型的数据)。
String str = "2022-07-09";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date parse = simpleDateFormat.parse(str);
String format = simpleDateFormat.format(parse);
System.out.println(format);
2.字符串、字节数组进行转换
2.1字符串转换为字节数组
使用getBytes()方法。
String str = "abc";
byte[] bytes = str.getBytes();
for (byte aByte : bytes) {
System.out.println(aByte);
}
2.2字节数组转换为字符串
1.使用new String(字节数组)
2.使用String valueOf(字节数组)
3字符串、字符数组的转换
1.字符串转换为字符数组:toCharArray()
2.字符数组转换为字符串:String.valueOf(字符数组)