Apache Commons Collections Collectionutils Tool class simple to use

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.