Collectionutils provides many ways to manipulate collections , and the common methods are as follows
import org.apache.commons.collections.collectionutils;import java.util.arraylist;import java.util.list;public class collectionutilstest { public Static void main (String[] args) { List< Integer> a = new arraylist<integer> (); List<Integer> b = null; List< Integer> c = new arraylist<integer> (); c.add (5); c.add (6); //determines whether the collection is empty system.out.println ( Collectionutils.isempty (a)); //true System.out.println (Collectionutils.isempty (b)); &NBSP;&NBSP;&NBsp;//true system.out.println (CollectionUtils.isEmpty (c)); //false //determines whether the collection is not empty system.out.println (Collectionutils.isnotempty (a)); //false system.out.println (Collectionutils.isnotempty (b)); False system.out.println (Collectionutils.isnotempty (c)); //true //operation between two sets List<Integer> e = new ArrayList<Integer> (); e.add (2); e.add (1); List<Integer> f = new ArrayList< Integer> (); &Nbsp; f.add (1); f.add (2); List<Integer> g = new ArrayList<Integer> (); g.add ( //); Compare two set-valued system.out.println (Collectionutils.isequalcollection (e,f )); //true system.out.println ( Collectionutils.isequalcollection (f,g)); //false List<Integer> h = new ArrayList<Integer> (); h.add (1); h.add (2); h.add (3);; List<Integer> i = new ArrayList< Integer> (); i.add (3); i.add (3); i.add (4); i.add (5); // system.out.println (Collectionutils.union (i,h)); //[1, 2, 3, 3, 4, 5] //intersection System.out.println (Collectionutils.intersection (i,h)); //[3] The complement of the //intersection system.out.println (collectionutils.disjunction (i, h)); //[1, 2, 3, 4, 5] //e and H difference system.out.println (Collectionutils.subtract (h,i)); //[1, 2 ] &Nbsp; system.out.println (Collectionutils.subtract (i,h)); //[3, 4, 5] }}
Apache Commons Collections Collectionutils Tool class simple to use