我有2 HashSet
Set<String> firstSet = new HashSet<String>();
Set<String> secondSet= new HashSet<String>();假设
firstSet包含字符串作为[A-ABC,B-BCD,C-CDE,D-DEF,L-POK];
secondSet包含字符串作为[A,B,C,D,L,K,M];
我是否可以在firstSet中分割每个元素,比如A,B,C,而不使用for loop,然后再做
firstSet.contains(secondSet);或者他们有什么合适的方法来做这件事?
发布于 2013-08-24 19:30:29
让firstSet成为地图。
final Map map<String, String> = new HashMap<String, String();
map.put("A", "ABC");
map.put("B", "BCD");
...
map.keySet().containsAll(secondSet);如果这不能解决你的问题,也许你可以更详细地解释一下你想要完成的事情。如果不遍历集合的每个元素,就无法对集合的每个元素进行操作。
https://stackoverflow.com/questions/18422250
复制相似问题