没找到轮子,简单写一下
// 方法1: private ListgetDuplicateCharacters(String checkWord, String key) { List characters = new ArrayList<>(); Arrays.stream(key.split("")).forEach(character -> { if (checkWord.contains(character)) { characters.add(character); } }); return characters; } // 方法2: private Pattern BLANK_SPLIT_PATTERN = Pattern.compile(""); private List getDuplicateCharacters(String checkWord, String key) { if (Strings.isNullOrEmpty(checkWord) || Strings.isNullOrEmpty(key)) { return new ArrayList<>(); } return BLANK_SPLIT_PATTERN.splitAsStream(key).filter(character -> checkWord.contains(character)).collect( Collectors.toList()); }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)