Java8 Previous procedure:
/*** Intersect from a list of values *@paramLists *@return */ PublicList<object> Intersection (list<list<object>>lists) { if(Lists = =NULL|| Lists.size () = = 0){ return NULL; } ArrayList<List<Object>> arrayList =NewArraylist<>(lists); for(inti = 0; I < arraylist.size (); i++) {List<Object> list =Arraylist.get (i); //Remove an empty collection if(List = =NULL|| List.size () = = 0) {arraylist.remove (list); I-- ; } } if(arraylist.size () = = 0){ return NULL; } List<Object> intersection = Arraylist.get (0) ; //There is only one non-empty collection, and the result is that he if(arraylist.size () = = 1){ returnintersection; } //There are multiple non-empty collections that intersect directly for(inti = 1; I < Arraylist.size ()-1; i++) {Intersection.retainall (Arraylist.get (i)); } returnintersection; }
Stream-style:
Public Static List<element> retainelementlist (list<list<element>> elementlists) { Optional<List<Element>> result = Elementlists.parallelstream () null & & (List) elementlist. Size ()! = 0) , { a.retainall (b); return A; }); return result.orelse (new arraylist<>()); }
Java8 lambda expression multiple list fetch intersection