The following is a java4android video tutorial from marschen.
The class set framework is the class and interface provided by JDK.
Main content of this set.
1. Collection and iterator Interfaces
2. How to Use set and hashset
Collection Interface
Boolean add adds an object to the set
Clear deletes all objects in the set.
Isempty determines whether the set is empty
Remove deletes an object reference from the collection.
Int size (); returns the number of elements in the set.
A sub-interface of collection is set.
The Set interface has an implementation class that is hastset.
Import Java. util. set; import Java. util. hashset; public class test {public static void main (string ARGs []) {hashset <string> hashset = new hashset <string> (); set <string> set = hashset; // set <stinrg> set = new hashset <string> (); Boolean b1 = set. isempty (); system. out. println (B1); set. add ("A"); set. add ("B"); set. add ("C"); set. add ("D"); Boolean b2 = set. isempty (); system. out. println (B2); int I = set. size (); system. out. println ("the length of the Set object before removing is" + I); // set. clear (); set. remove ("A"); Int J = set. size (); system. out. println ("the length of the Set object after removing is" + J );}}
Import Java. util. set; import Java. util. hashset; import Java. util. iterator; public class test1 {public static void main (string ARGs []) {// hashset <string> hashset = new hashset <string> (); // set <string> set = hashset; // iterator <-- collection <--- set <----- hashset // <--- list <---- arraylist // hasnext () Next () set <string> set = new hashset <string> (); set. add ("A"); set. add ("B"); set. add ("C"); set. add ("D"); // call the iterator method of the set object to generate an iterator object, which is used to discard the entire set object. iterator <string> it = set. iterator (); // generates an iterator object. /* Boolean b1 = it. hasnext (); If (B1) {string S = it. next (); system. out. println (s);} Boolean b2 = it. hasnext (); If (B2) {string S = it. next (); system. out. println (s);} */while (it. hasnext () {string S = it. next (); system. out. println (s );}}}