cn.hutool.core.text.ASCIIStrCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hutool-all Show documentation
Show all versions of hutool-all Show documentation
Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。
package cn.hutool.core.text;
/**
* ASCII字符对应的字符串缓存
*
* @author looly
* @since 4.0.1
*
*/
public class ASCIIStrCache {
private static final int ASCII_LENGTH = 128;
private static final String[] CACHE = new String[ASCII_LENGTH];
static {
for (char c = 0; c < ASCII_LENGTH; c++) {
CACHE[c] = String.valueOf(c);
}
}
/**
* 字符转为字符串
* 如果为ASCII字符,使用缓存
*
* @param c 字符
* @return 字符串
*/
public static String toString(char c) {
return c < ASCII_LENGTH ? CACHE[c] : String.valueOf(c);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy