markdown
### String 相关类
```text
#String 存储在字符串常量池中
public final class String extends Object implements Serializable, Comparable, CharSequence, Constable, ConstantDesc
#String与变量拼接以后,结果在堆中,使用intern()方法,返回值就在常量池中
```
#### 编码 解码
```text
String.getBytes("GBK")
String str3 = new String(Bytes,"GBK");
```
#### StringBuffer/StringBuilder
```text
共通之处在于,两者是可变的,而String 是不可变的
三者同样使用char[] 存储
```
```text
StringBuffer
* 线程安全
* 效率低
StringBuilder
* 线程不安全
* 效率高
```
### LocalDate/LocalTime/LocalDateTime
具体方法便不多解释
### Instant
```text
Instant l = Instant.now();
System.out.println(l.toString());
System.out.println(l.toEpochMilli());
OffsetDateTime offsetDateTime = l.atOffset(ZoneOffset.ofHours(8));
System.out.println(offsetDateTime.toEpochSecond());
System.out.println(offsetDateTime.toString());
System.out.println(System.currentTimeMillis());
```
#### DateTimeFormatter
```text
#格式化
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy:MM:dd hh:mm:ss");
System.out.println(LocalDateTime.now().format(dateTimeFormatter));
#解析
TemporalAccessor parse = dateTimeFormatter.parse("2023:04:06 08:29:01");
```
### 比较器相关类
```text
#对象的大小排序
自然排序: Comparable #自定义类需要排序
定制排序: Comparator #临时性排序
```
*
*[返回教程主页](https://www.monody.net/p/blog-page_3.html)*
*
评论