Set-related knowledge:
1 PackageOrg.hanqi.array;2 3 ImportJava.util.*;4 5 Public classTest2 {6 7 Public Static voidMain (string[] args) {8 9 //int i;//default I=0Ten //int [] m = new int[5];//assigned a value of 5 a 0 One A //Hash -set<string> s =NewHashset<string>(); -hashset<string> S1 =NewHashset<string>(); the - if(S.add ("a")) - { -System.out.println ("Save a Success"); + } -S.add ("B"); +S.add ("C"); AS.add ("D"); atS.add ("E"); -S.add ("F"); -S.add ("G"); - - if(!s.add ("a")) - { inSystem.out.println ("Save a Failed"); - } to //S.add ("a"); + //S.add ("a"); - the for(String t:s) * { $ System.out.print (t);Panax Notoginseng } - the System.out.println (); + ASystem.out.println ("s size=" +s.size ()); the + if(S.remove ("D")) - { $System.out.println ("Removal succeeded"); $ } - Else - { theSystem.out.println ("Removal failed"); - }Wuyi theSystem.out.println ("s size=" +s.size ()); - Wu //iterators -Iterator<string> it =s.iterator (); About while(It.hasnext ()) $ { -String T =It.next (); - if(T.equals ("C")) - { A It.remove (); + } the Else - { $ System.out.print (t); the } the the } the - System.out.println (); in theSystem.out.println ("s size=" +s.size ()); the AboutSystem.out.println ("TreeSet"); the theset<string> s2 =NewTreeset<string>(); the +S2.add ("F"); -S2.add ("B"); theS2.add ("D");BayiS2.add ("C"); theS2.add ("E"); theS2.add ("a"); -S2.add ("G"); - the for(String t:s2) the { the System.out.print (t); the } - the System.out.println (); the theSystem.out.println ("S2 's size=" +s2.size ());94 } the}
The result of the operation is:
Map Related knowledge:
1 PackageOrg.hanqi.array;2 3 ImportJava.util.*;4 5 Public classTest3 {6 7 Public Static voidMain (string[] args) {8 9map<string,string> m =NewHashmap<string,string>();Ten OneM.put ("7", "Zibo"); AM.put ("9", "Jinan"); -M.put ("5", "Qingdao"); -M.put ("1", "Qingdao"); theM.put ("8", "Qingdao"); -M.put ("6", "Qingdao"); -M.put ("3", "Qingdao"); -M.put ("2", "Qingdao"); +M.put ("0", "Qingdao"); - //length +System.out.println ("length =" +m.size ()); AM.put ("0534", "Qingdao"); atM.put (NULL,NULL); -System.out.println ("length =" +m.size ()); - //get value based on key -System.out.println ("0533=" +m.get ("0533")); - //if key exists - if(M.containskey ("0533")) in { -System.out.println ("Key 0533 already exists"); to } + //value is present - if(M.containsvalue ("Zibo")) the { *System.out.println ("Value Zibo already exists"); $ }Panax Notoginseng //Traverse - for(String k:m.keyset ()) the { +System.out.println (k + "=" +M.get (k)); A } the } +}
The result of the operation is:
Related Mind Mapping:
Classroom-Organized: set and map