12th Day Content

Source: Internet
Author: User


Homework:

1. Describe the HASHMAP internal implementation principle.

HashMap is K-v, K is the only one that does not repeat.

Principle:

) Then the value and the capacity of the collection (typically 15) are performed with the operation, resulting in a value between 0-15 that represents the array subscript where the element falls, that is, where the element is stored in the array. Hash hashing method is more efficient, for keyword search algorithm, when searching for an element, through the hash method can drop the search scope in the specified location,


2. Describe the difference between hashset and HashMap.

The Hashset:hashset collection is implemented internally through HashMap. The key part of HashMap is used. Implement set interface, set inherit collection interface

HashMap: To implement the map interface, the map interface and the collection interface are peers.

They all have the characteristics of non-repetition and are stored using the hash mechanism.


3. The collection of grades uses a nested implementation of map.

Class 10, 50 people per class.


Code:

package twelve;import java.util.hashmap;import java.util.map;import java.util.map.entry; Import java.util.set;public class nestmapdemo {public static void main ( String[] args)  {map<integer,map<string,string>> classes=new hashmap<integer ,map<string,string>> (); map<string,string> students = null ;//class for (int i=1;i<11;i++) {// Students of each class students = new hashmap<string,string> (); Classes.put (i,students); for (int j=1;j <51;j++) {students.put (i+ ".") +j,  "kal " +j);}} SYSTEM.OUT.PRINTLN ("EntrySet traversal =========================")  ;for (entry<integer,map<string,string> > classe :classes.entryset ()) {//  class Integer classnos=classe.getkey (); Map<string,string> studentsmap=classe.getvalue (); for (entry<string,string> entry :  studentsmap.entryset ()) {String stuno = entry.getkey();//name String stuname = entry.getvalue (); System.out.println ("Class  "  +classnos +  "  study number  "  + stuNo +  "   students   " + stuname)  ;}} SYSTEM.OUT.PRINTLN ("Keyset traversal =========================")  ;for (integer classno :  Classes.keyset ()) {map<string,string> studentsmap=classes.get (Classno); for (String studentno  :studentsmap.keyset ()) {System.out.println ("Class: " +classno+ " : " +studentno+ "  Students:   "+studentsmap.get (Studentno));}}} Results Part/** entryset traverse ========================= Class  1  study number  1.23  student  kal 23 class  1   Number  1.24  student  kal 24 class  1  study number  1.21  student  kal 21 class  1  School Number  1.22  student  kal 22 class  1  study number  1.20  student  kal 20 class  1  study No.  1.18  student  kal 18 Class  1  study number  1.19  student  kal 19 class  1  study number   1.16  Student  kal 16 class  1  study number  1.17  student  kal 17 class  1  student number  1.14  students  kal 14 Class  1  School Number  1.15  student  kal 15 class  1  study number  1.34  students   Kal 34 Class  1  School Number  1.35  student  kal 35 class  1  study number  1.32  student  kal  32 Class  1  School Number  1.33  student  kal 33 class  1  study number  1.30  students  Kal  30 Class  1  Study number  1.31  student  kal 31 class  1  student number  1.29   kal 29 class  1  Number  1.1  student  kal 1 class  1  study number  1.27  student  kal 27 class  1   Number  1.2  student  kal 2 class  1  study number  1.28  student  kal 28 class  1  study No.  1.3  student  kal 3 Class  1  study number  1.25  student  kal 25 class  1  study number   1.4  student  kal 4 Class  1  study number  1.26  student  kal 26 class  1  study number  1.5   Student  kal 5 ClassClass  1  number  1.6  student  kal 6 class  1  study number  1.7  student  kal 7 class  1   Number  1.8  student  kal 8 class  1  study number  1.9  student  kal 9 class  1  study No.  1.45  student  kal 45 Class  1  study number  1.46  student  kal 46 class  1  study number   1.43  student  kal 43 Class  1  study number  1.44  student  kal 44 class  1  study number  1.41   Student  kal 41 Class  1  study number  1.42  student  kal 42 class  1  study number  1.40  Student &NBSP;KAL&NBSP;40 Class  1  study number  1.38  student  kal 38 class  1  student number  1.39  students  kal 39 Class  1  School Number  1.36  student  kal 36 class  1  study number  1.37  students   Kal 37 Class  1  School Number  1.12  student  kal 12 class  1  study number  1.13  student  kal  13 Class  1  School Number  1.10  student  kal 10 class  1  study number  1.11  students  Kal  11 Class  1  Study No.  1.50  student &NBSP;KAL&NBSP;50 Class  1  study number  1.49  student  kal 49 class  1  study number  1.47   Students  kal 47 Class  1  study number  1.48  student  kal 48 class  10  study number  10.50   Students &NBSP;KAL&NBSP;50 Class  10  study number  10.11  student  kal 11 class  10  study number  10.10   Students &NBSP;KAL&NBSP;10 Class  10  study number  10.13  student  kal 13 class  10  study number  10.12   Students  kal 12 Class  10  study number  10.15  student  kal 15 class  10  study number  10.14   Students  kal 14 Class  10  study number  10.17  student  kal 17 class  10  study number  10.16   Students  kal 16 Class  10  study number  10.19  student  kal 19 class  10  study number  10.18   Students  kal 18 Class  10  study number  10.20  student &NBSP;KAL&NBSP;20 class  10  study number  10.22   Students  kal 22 Class  10  study number  10.21  student  kal 21 class  10  study number  10.6   Student  kal 6 class &NBsp;10   10.5  student  kal 5 class  10  student number  10.4   kal 4 class  10   Number  10.3  student  kal 3 class  10  study number  10.2  student  kal 2 class  10  School Number  10.1  student  kal 1 class  10  study number  10.24  student  kal 24 class  10  study No.  10.23  student  kal 23 Class  10  study number  10.26  student  kal 26 class  10  School Number  10.25  student  kal 25 Class  10  study number  10.28  student  kal 28 class  10  School Number  10.9  student  kal 9 Class  10  study number  10.27  student  kal 27 class  10  School Number  10.8  student  kal 8 Class  10  study number  10.7  student  kal 7 class  10  study number   10.29  student  kal 29 Class  10  study number  10.31  student  kal 31 class  10  study number   10.30  student  kal 30 Class  10  study number  10.33  student  kal 33 class  10  study number   10.32  Student &NBSP;KAL&NBSp;32 Class  10  School Number  10.35  student  kal 35 class  10  study number  10.34  student  kal  34 Class  10  School Number  10.37  student  kal 37 class  10  study number  10.36  student  kal  36 Class  10  School Number  10.39  student  kal 39 class  10  study number  10.38  student  kal  38 Class  10  School Number  10.40  student  kal 40 class  10  study number  10.42  student  kal  42 Class  10  School Number  10.41  student  kal 41 class  10  study number  10.44  student  kal  44 Class  10  School Number  10.43  student  kal 43 class  10  study number  10.46  student  kal  46 Class  10  School Number  10.45  student  kal 45 class  10  study number  10.48  student  kal  48 Class  10  School Number  10.47  student  kal 47 class  10  study number  10.49  student  kal  49keyset Traversal ========================= */








12th Day Content

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.