Java Compare Two Lists

后端 未结 10 594
情深已故
情深已故 2020-11-22 13:25

I have two lists ( not java lists, you can say two columns)

For example

**List 1**            **Lists 2**
  milan                 hafil
  dingo               


        
10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 13:52

    Assuming hash1 and hash2

    List< String > sames = whatever
    List< String > diffs = whatever
    
    int count = 0;
    for( String key : hash1.keySet() )
    {
       if( hash2.containsKey( key ) ) 
       {
          sames.add( key );
       }
       else
       {
          diffs.add( key );
       }
    }
    
    //sames.size() contains the number of similar elements.
    

提交回复
热议问题