简体   繁体   中英

Searching in HashSet

I have 2 HashSet

Set<String> firstSet = new HashSet<String>();
Set<String> secondSet= new HashSet<String>();

Suppose

firstSet contains String as [A-ABC,B-BCD,C-CDE,D-DEF,L-POK] ;

secondSet contains String as [A,B,C,D,L,K,M] ;

Can i split each elements within firstSet like [A,B,C] without for loop and then do

firstSet.contains(secondSet);

or is their any appropriate way for doing this ?

Make firstSet instead a Map.

final Map map<String, String> = new HashMap<String, String();
map.put("A", "ABC");
map.put("B", "BCD");
...


map.keySet().containsAll(secondSet);

If that doesn't address your issue, perhaps you could explain in a bit more detail what you're trying to accomplish. There is no way to act on every element of a set without walking through every element of the set.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM