public boolean containsPrefixOf ( String s ) { SortedSet < String > sub = headSet ( s ) ; // because redundant prefixes have been eliminated, // only a test against last item in headSet is necessary if ( ! sub . isEmpty ( ) && s . startsWith ( ( String ) sub . last ( ) ) ) { return true ; // prefix substring exists } // else: might still exist exactly (headSet does not contain boundary) return contains ( s ) ; // exact string exists, or no prefix is there }
Test whether the given String is prefixed by one of this set s entries .