迭代哈希 [英] Iterating Hashsets
本文介绍了迭代哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
早上好!
我有一个具有不同对象的哈希集
I have a hashset which has different objects
对象具有属性
GroupName 机器名称 电子邮件地址
GroupName MachineName EmailAddress
现在,从HashSet中,我必须找到具有相同MachineName和EmailAddress但具有不同Group的对象,并将其添加到数组列表中.
Now from the HashSet I have to find the Object which has same MachineName and EmailAddress but different Group and add into an arraylist.
谢谢
推荐答案
一个大的假设是您正在使用Java:
A big assumption is that you are using Java:
Set<YourObject> yourHashSet = //
List<YourObject> result = new ArrayList<YourObject>();
for( YourObject o: yourHashSet ){
if( o.getMachineName().equals("machine1") && o.getEmailAddress().equals("one@example.com")){
result.add(o);
}
}
// result will contain a list of matching objects.
任何语言中的代码几乎都是相同的,但是如果您使用的是C#,则可以使用LINQ-Objects在一个漂亮的单一语句中完成某些事情.
It's pretty much the same code in any language, but if you are in C# you can use LINQ-Objects to do the something in a nice single statement.
这篇关于迭代哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文