String (List<Mapping> mappings, List<String> initials) { Map<String, Character> encoding = initials.stream() .collect(Collectors.toMap(s -> s, s -> (char)(PinyinMatcher.BASE_CHAR + initials.indexOf(s)))); Map<Integer, Character> map = mappings.stream() .collect(Collectors.toMap(mapping -> mapping.codePoint, m -> encoding.get(m.charString()))); int lastCodePoint = mappings.stream().mapToInt(m -> m.codePoint).max().orElseThrow(NoSuchElementException::new); return IntStream.rangeClosed(PinyinMatcher.BASE_CODE_POINT, lastCodePoint) .mapToObj(i -> map.getOrDefault(i, ' ').toString()).collect(Collectors.joining()); }