Java Set equality ignore case

前端 未结 6 1475
渐次进展
渐次进展 2020-12-11 00:14

I want to check if all elements of two sets of String are equal by ignoring the letter\'s cases.

Set set1 ;
Set set2 ;
.
.
.
if(s         


        
6条回答
  •  無奈伤痛
    2020-12-11 00:45

    Untested, but this is the general idea:

    public boolean setEqualsIgnoreCase(Set a, Setb)
    {
        if (a.size() != b.size()) return false;
        Iterator ai = a.iterator();
        Iterator bi = b.iterator();
        while(ai.hasNext())
        {
             if (!ai.next().equalsIgnoreCase(bi.next())) return false;
        }
        return true;
    }
    

提交回复
热议问题