Textbook 235 Pages 2-3 Questions

Source: Internet
Author: User

 PackageOrg.hanqi.array;ImportJava.util.*; Public classXiti2 { Public Static voidMain (string[] args) {List<String> list=NewArraylist<string>(); List.add (A); List.add (A); List.add (C); List.add (C); List.add (A);  for(String s:list) {System.out.println (s); } System.out.println ("Set length =" +list.size ()); System.out.println ("List collection successfully added"); HashSet<string>s1=NewHashset<string>(); S1.add (A); S1.add (A); S1.add (C); S1.add (C); S1.add (A);  for(String t:s1) {System.out.println (t); } System.out.println ("Set length =" +s1.size ()); System.out.println ("Set collection cannot be added successfully"); }}
View Code

 PackageOrg.hanqi.array;ImportJava.util.HashMap;ImportJava.util.Map; Public classEMP {PrivateString Key; PrivateString value;  PublicEmp (String key,string value) { This. key=key;  This. value=value; }     PublicString GetKey () {returnkey; }     Public voidSetkey (String key) { This. Key =key; }     PublicString GetValue () {returnvalue; }     Public voidSetValue (String value) { This. Value =value; }     Public Static voidMain (string[] args) {Map<string, string>m=NewHashmap<string, string>(); EMP EMP=NewEMP ("001", "Texas Braised Chicken"); EMP EMP2=NewEMP ("002", "Peking Roast Duck")); EMP Emp3=NewEMP ("003", "absolute duck Head"); EMP Emp4=NewEMP ("004", "Boshan pastry pot"); EMP EMP5=NewEMP ("005", "Wuhan Hot-Noodle"); EMP EMP6=NewEMP ("006", "Zhoucun pancake"); EMP EMP7=NewEMP ("007", "Zibo BBQ");        M.put (Emp.getkey (), Emp.getvalue ());        M.put (Emp2.getkey (), Emp2.getvalue ());        M.put (Emp3.getkey (), Emp3.getvalue ());        M.put (Emp4.getkey (), Emp4.getvalue ());        M.put (Emp5.getkey (), Emp5.getvalue ());        M.put (Emp6.getkey (), Emp6.getvalue ());                M.put (Emp7.getkey (), Emp7.getvalue ());        M.remove (EMP5);  for(String t:m.keyset ()) {if(t== "005") {m.remove (EMP5); }            Else{System.out.println (t); }        }    }}
View Code

Textbook 235 Pages 2-3 Questions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.