一、导入依赖
<dependency>
<groupId>com.jianggujin</groupId>
<artifactId>IKAnalyzer-lucene</artifactId>
<version>8.0.0</version>
</dependency>
二、开始分词
@Test
void contentBlock() throws IOException {
String content = "你好中国";
Analyzer anal = new IKAnalyzer(true);
StringReader reader = new StringReader(content);
TokenStream ts = anal.tokenStream("", reader);
ts.reset();
CharTermAttribute term = ts.getAttribute(CharTermAttribute.class);
while (ts.incrementToken()) {
String s = term.toString();
System.out.println(s);
}
reader.close();
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/36071be1cfc34b5180f33e6075877889.png)