TextEncoder().encode 的等效 java 函数

equivalent java function of TextEncoder().encode

encoder.encode 的等效 java 函数是什么。我想将以下 JavaScript 函数转换为 java .

function fun(){
const encoder = new TextEncoder()
const view = encoder.encode('xxx').buffer
console.log(view); 

}

但问题是找不到任何等效代码来获得相似的结果

import java.nio.charset.StandardCharsets;



byte[] view = "xxx".getBytes(StandardCharsets.UTF_8);