Iterating Hashsets

孤人 提交于 2019-12-11 18:51:57

问题


Good morning guys

I have a hashset which has different objects

Object has attributes

GroupName MachineName EmailAddress

Now from the HashSet I have to find the Object which has same MachineName and EmailAddress but different Group and add into an arraylist.

thanks


回答1:


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.

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.



来源:https://stackoverflow.com/questions/6212325/iterating-hashsets

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!