0
点赞
收藏
分享

微信扫一扫

String类的getBytes()方法

自信的姐姐 2022-01-26 阅读 81


​String​​​类的​​getBytes()​​方法

1.方法简介

/**
* Encodes this {@code String} into a sequence of bytes using the given
* {@linkplain java.nio.charset.Charset charset}, storing the result into a
* new byte array.
将这个String以给定的charset 编码成一个字节序列,并将这个结果存储到一个新的字节数组中
*
* <p> This method always replaces malformed-input and unmappable-character
* sequences with this charset's default replacement byte array. The
* {@link java.nio.charset.CharsetEncoder} class should be used when more
* control over the encoding process is required.

*
* @param charset
* The {@linkplain java.nio.charset.Charset} to be used to encode
* the {@code String}
*
* @return The resultant byte array 结果生成的字节数组

* @since 1.6
*/
public byte[] getBytes(Charset charset) {
if (charset == null) throw new NullPointerException();
return StringCoding.encode(charset, value, 0, value.length);
}

2.方法使用



举报

相关推荐

0 条评论