Contains a set of operations (), containsAll (), addAll (), removeAll (),

package seday11;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
/**
* @author xingsir
* 集合的操作
*/
public class CollectionDemo3 {

static void main public (String [] args) {
// create a collection c1, orderly and repeatable
Collection new new C1 = the ArrayList ();
c1.add ( "C #");
c1.add ( "C ++");
C1. the Add ( "the Java");
System.out.println (c1); // Print
// create a collection c2, unrepeatable
collection c2 = new new HashSet ();
c2.add ( "c #");
c2.add ( "c ++ ");
c2.add (" the Java ");
System.out.println (c2); // Print

c1.addAll (c2); // addAll ( ), all elements of a given set are added to the current collection
System.out.println (c1); // print
c2.addAll (c1); // addAll ( ) All elements in the given set is added to the current collection
System.out.println (c2); // Print

// create a collection c3
collection c3 = new new ArrayList ();
c3.add ( "c ++");
c3. the Add ( "Python");
/ *
* Boolean the contains (E E)
* determines whether the current set of the given element, is determined according to the comparison element equals.
* /
Boolean c1.contains the contains = ( "C #");
System.out.println ( "whether there is comprising:" + contains);

/ *
* Boolean containsAll (Collection C)
* determines the current collection contains all the elements of a given set.
* /
The contains = c2.containsAll (C3);
System.out.println ( "whether or not all-inclusive:" + contains);

/ *
* Delete the current set of elements shared with a given set of (delete intersection) removeAll ()
* /
c1.removeAll (c3);
System.out.println (c1);

}

 

}

Guess you like

Origin www.cnblogs.com/xingsir/p/12089905.html