First question:
1 ImportJava.util.*;2 3 Public classListtest {4 5 6 Public Static voidMain (string[] args) {7 8arraylist<integer> list =NewArraylist<integer>();9 Ten for(inti=0;i<101;i++){ One A List.add (i); - } -System.out.println ("original data: \ n" +list); the -List.remove (10); - -SYSTEM.OUT.PRINTLN ("Data after removal: \ n" +list); + } -}
Results of the operation:
The original data:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60 3, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
After removing the data:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61 4, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
The second question:
1 ImportJava.util.*;2 3 Public classSetlist {4 5 Public Static voidMain (string[] args) {6 7arraylist<string> list =NewArraylist<>();8Hashset<string> set =NewHashset<string>();9Treeset<string> Set1 =NewTreeset<string>();Ten OneCollections.addall (list, "a", "a", "C", "C", "a"); ACollections.addall (Set, "a", "a", "C", "C", "a"); -Collections.addall (Set1, "a", "a", "C", "C", "a"); - theSYSTEM.OUT.PRINTLN ("List of data: \ t" +list); -SYSTEM.OUT.PRINTLN ("Set data: \ t" +set); -SYSTEM.OUT.PRINTLN ("Set data: \ t" +Set1); - + } -}
Results of the operation:
List data: [A, A, C, C, a]
Set data: [C, A, C, a]
Set data: [A, C, a, c]
Question three:
1 ImportJava.util.*;2 3 Public classTestMap {4 5 Public Static voidMain (string[] args) {6 7EMP e1 =NewEMP ("001", "Xiao Zhao");8EMP e2 =NewEMP ("002", "Penny");9EMP E3 =NewEMP ("003", "little grandchild");TenEMP e4 =NewEMP ("004", "Xiao Li"); OneEmp e5 =NewEMP ("005", "Small Week"); AEMP e6 =NewEMP ("006", "Xiao Wu"); - -hashmap<string,string> m =NewHashmap<string,string>(); the - M.put (E1.getid (), E1.getname ()); - M.put (E2.getid (), E2.getname ()); - M.put (E3.getid (), E3.getname ()); + M.put (E4.getid (), E4.getname ()); - M.put (E5.getid (), E5.getname ()); + M.put (E6.getid (), E6.getname ()); A atSYSTEM.OUT.PRINTLN ("raw data: \ n" +m); - -M.remove ("005"); - -SYSTEM.OUT.PRINTLN ("Data after removal: \ n" +m); - in - } to } + classemp{ - the PrivateString ID; * PrivateString name; $ PublicEMP (string ID, string name) {Panax Notoginseng Super(); - This. ID =ID; the This. Name =name; + } A PublicString getId () { the returnID; + } - Public voidsetId (String id) { $ This. ID =ID; $ } - PublicString GetName () { - returnname; the } - Public voidsetName (String name) {Wuyi This. Name =name; the } - Wu}
Results of the operation:
The original data:
{004= Xiao Li, 005= Xiao Zhou, 006= Xiao Wu, 001= xiao Zhao, 002 = Penny, 003= Xiao Sun}
After removing the data:
{004= Xiao Li, 006= Xiao Wu, 001= xiao Zhao, 002 = Penny, 003= Xiao Sun}
About the collection of exercise p235-1,2,3