Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HashSet contains substring

Tags:

java

I have a HashSet of Strings in the format: something_something_name="value"

Set<String> name= new HashSet<String>();

Farther down in my code I want to check if a String "name" is included in the HashSet. In this little example, if I'm checking to see if "name" is a substring of any of the values in the HashSet, I'd like it to return true.

I know that .contains() won't work since that works using .equals(). Any suggestions on the best way to handle this would be great.

like image 307
joshft91 Avatar asked Oct 25 '25 23:10

joshft91


1 Answers

With your existing data structure, the only way is to iterate over all entries checking each one in turn.

If that's not good enough, you'll need a different data structure.

like image 57
NPE Avatar answered Oct 28 '25 11:10

NPE