International Component for Unicode for Java (ICU4J) 这个库提供了各种处理Unicode和国际化的工具
添加依赖
代码语言:javascript复制<!-- https://mvnrepository.com/artifact/com.ibm.icu/icu4j -->
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>72.1</version>
</dependency>
处理全角半角转换
代码语言:javascript复制import com.ibm.icu.text.Transliterator;
// 全角转半角
Transliterator fToHTransliterator = Transliterator.getInstance("Fullwidth-Halfwidth");
System.out.println(fToHTransliterator.transliterate("ABC"));
// 半角转全角
Transliterator hToFTransliterator = Transliterator.getInstance("Halfwidth-Fullwidth");
System.out.println(hToFTransliterator.transliterate("ABC"));