Java List Intersect intersect(List lst1, List lst2)

Here you can find the source of intersect(List lst1, List lst2)

Description

intersect

License

Apache License

Declaration

public static void intersect(List lst1, List lst2) 

Method Source Code

//package com.java2s;
/**/*from  ww  w. j  av  a2s.  co  m*/
 * Copyright 2016 William Van Woensel
    
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
    
   http://www.apache.org/licenses/LICENSE-2.0
    
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 * 
 * 
 * @author wvw
 * 
 */

import java.util.List;

public class Main {
    public static void intersect(List lst1, List lst2) {
        for (int i = 0; i < lst1.size(); i++) {
            Object obj1 = lst1.get(i);

            if (!lst2.contains(obj1))
                lst1.remove(i--);
        }
    }

    public static boolean contains(List lsttor, Object val) {
        for (int i = 0; i < lsttor.size(); i++)
            if (lsttor.get(i).equals(val))
                return true;

        return false;
    }

    public static boolean equals(List lst1, List lst2) {
        if (lst1.size() != lst2.size())
            return false;

        for (Object obj1 : lst1) {

            boolean match = false;
            for (Object obj2 : lst2) {

                if (obj1.equals(obj2)) {
                    match = true;

                    break;
                }
            }

            if (!match)
                return false;
        }

        return true;
    }
}

Related

  1. getIntersectionOfLineAndSegments(double x1, double y1, double x2, double y2, List segmentPoints)
  2. hasIntersection(List list1, List list2)
  3. hasIntersection(Set set, List list)
  4. Intersect(List A, List B)
  5. intersect(List ls, List ls2)
  6. intersect(List list1, List list2)
  7. intersect(List... lists)
  8. intersect(List in1, List in2)
  9. intersect(Set a, List b)