开发者

Iterating Hashsets

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 arr开发者_JAVA百科aylist.

thanks


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜