以下是写业务时碰到的需求,正好看到部分有部分人有这个疑问希望能帮到各位,话不多说代码如下: //HJ-2089-8 截取符号"-"包含的部分 来判断是否同组 通过set集合去重 Set<String> codes4 = list.stream() .map(o -> { int firstDashIndex = o.indexOf("-"); int secondDashIndex = o.indexOf("-", firstDashIndex + 1); if (firstDashIndex != -1 && secondDashIndex != -1) { return o.substring(firstDashIndex + 1, secondDashIndex); } else { //编号格式不对直接返回"" return ""; } }) .collect(Collectors.toSet()); log.info("codes: {}", codes4); if (codes4.contains("")){ return Result.error("模具编码格式不对,请检查"); }
取两个符号中间的字符串
最新推荐文章于 2025-01-22 14:44:52 发布