// String
String[] split = cc.getTeacherPosition().split(REGEX);
if (!ArrayUtils.isEmpty(split) && split.length > 1) {
chaosCourseResponseDto.setTeacherPosition(split[1]);
}
// google
ArrayList<String> strings = Lists.newArrayList(Splitter.on(":").trimResults().split(cc.getTeacherPosition()));
if (!CollectionUtils.isEmpty(strings) && strings.size() > 1) {
chaosCourseResponseDto.setTeacherPosition(strings.get(1));
}
// 我就想用一行代码解决
Pattern.compile(REGEX).splitAsStream(cc.getTeacherPosition()).skip(1).findFirst().ifPresent(chaosCourseResponseDto::setTeacherPosition);
Java分割字符串并获取第几个字符串,优雅写法
最新推荐文章于 2024-07-19 03:08:56 发布