There is a sequence of objects with no duplicate elements in the collection.
Java provides the appropriate classes and interfaces to store such elements as--set rule sets.
Here's an example to learn the set collection schema, which contains comments:
Package com.brucezhang.test;
Import Java.util.HashSet;
Import Java.util.Iterator;
Import Java.util.LinkedHashSet;
Import Java.util.Set;
public class Settest {/** * @param args */public static void main (string[] args) { The TODO auto-generated method stub//hashset is a collection structure that stores data that is not as efficient as inserting data into the order///not in sequence set<st
ring> set = new hashset<string> ();
Set.add ("Beijing");
Set.add ("Shanghai");
Set.add ("Hefei");
Set.add ("Dalian");
/** * Because it is a collection schema, when inserting two identical elements, only a * */Set.add ("Guangzhou") is stored;
Set.add ("Guangzhou");
SYSTEM.OUT.PRINTLN (set);
Iterator iterator = Set.iterator ();
while (Iterator.hasnext ()) {//System.out.println (Iterator.next () + ""); }//For (Object element:set) {// System.out.println (element.tostring () + ""); * * * * When you need to use sequential storage, you need to use the Linkedhashset architecture, but not high efficiency * * */Set<s
tring> Set2 = new linkedhashset<string> ();
Set2.add ("Beijing");
Set2.add ("Shanghai");
Set2.add ("Hefei");
Set2.add ("Dalian");
/** * Because it is a collection schema, when inserting two identical elements, only a * */Set2.add ("Guangzhou") is stored;
Set2.add ("Guangzhou");
System.out.println (Set2);
Iterator iterator = Set.iterator ();
while (Iterator.hasnext ()) {//System.out.println (Iterator.next () + "");
}//For (Object Element:set2) {//System.out.println (element.tostring () + ""); // }
}
}
The results of the operation are as follows: