Add "a" "a" "C" "C" "a" 5 elements to the set collection and the list collection respectively, and observe whether the duplicate value "a" can be successfully added in the list collection as well as in the set collection.
Import java.util.ArrayList;
Import Java.util.HashSet;
Import Java.util.Iterator;
Import java.util.List;
Import Java.util.Set;
public class Addintosetandlist {
public static void Main (string[] args) {
TODO auto-generated Method Stub
Set<string> set=new hashset<string> ();
Set.add ("A");
Set.add ("a");
Set.add ("C");
Set.add ("C");
Set.add ("a");
Iterator It=set.iterator ();
while (It.hasnext ()) {
System.out.println ("Set printout Data" +it.next ());
}
List<string> list=new arraylist<string> ();
List.add ("A");
List.add ("a");
List.add ("C");
List.add ("C");
List.add ("a");
Iterator It1=list.iterator ();
while (It1.hasnext ()) {
System.out.println ("Need to print out data:" +it1.next ());
}
}
}
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/21/wKioL1V0--zBFBHSAAEDYgR-9wk589.jpg "title=" 60.JPG "alt=" Wkiol1v0--zbfbhsaaedygr-9wk589.jpg "/>
Set and list collation (set is unordered list is ordered)