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.
精彩评论