String (String base, List<?> unsortedList) { int minLen = base.length(); int maxLen = Integer.MAX_VALUE; String ret = null; Iterator<Choice> it = getAlphabeticallySortedContent().tailSet( new Choice(base, base), true) .iterator(); Iterator<?> its = unsortedList.iterator(); while ((maxLen > minLen) && (it.hasNext() || its.hasNext())) { String s = it.hasNext() ? it.next().str : its.next().toString(); int match = ChoiceMatch.getMatchingLength(base, s, strComparator); if (match == minLen) { if (ret == null) { ret = s; maxLen = s.length(); } else { maxLen = Math.min(maxLen, ChoiceMatch.getMatchingLength(ret, s, strComparator)); } } } return (ret == null) ? "" : ret.substring(minLen, maxLen); }