[Method] list <?> List collection to find two different elements, differencing

// 1
  // own statement List 
       for ( int I = 0 ; I <list1.size (); I ++ ) 
        { 
            for ( int J = 0 ; J <list2.size (); J ++ ) {
                 IF (List1. GET . (i) .toString () the equals (. List2 GET (J) .toString ())) // find the same elements 
                { 
                    list1.remove (i); // delete list1 element at index i 
                    i-- ;              
 // delete the list element index becomes small to reduce the need to index values, list, and not as an array of space 
                    BREAK ; 
                } 
            }

        } 

// Method 2 

// Get set difference of two sets of 
    public List removeAll (the src List, List <?> <?> <?> Target) { 
        the LinkedList Result = <?> New new the LinkedList <> (the src); // with a large collection of LinkedList 
        HashSet targetHash = <?> new new HashSet <> (target); // small set with HashSet 
        iterator ITER = result.iterator () <?>; // use iterator iterator operation data of 

        the while (ITER. the hasNext ()) {
             IF (targetHash.contains (iter.next ())) { 
                iter.remove (); 
            } 
        } 
        return Result; 
    }

 

Guess you like

Origin www.cnblogs.com/suncos/p/11111390.html