Big Data Java Foundation 12th day job

Source: Internet
Author: User

Tag:java   hashmap    Big Data    io   

The first question: HashMap internal implementation Principle HashMap is a collection of key => value  pairs, each pair is a entry (entry), key and value are the object of the reference. Key cannot store duplicate values, and the set of key is keyset (). Value can have duplicate values, and the collection of value is values (). The HashMap is a hash (hash) algorithm, which makes the query value fast and efficient in map. HashMap judge whether the object is equal, first determine whether the hashcode is equal, and then determine whether the equals value is equal. Object Equality Code: (This.hashcode ()  == obj.hashcode ()  &&  (this == obj | |  this.equals (obj)) The second question: HashSet and HashMap difference hashset: Implement collection interface, only the collection of value, with the hash algorithm stored, value cannot be duplicated. HASHMAP: The implementation of the map interface, the collection of Key=>value, with the hash algorithm to store, key value can not be duplicated, the value may be repeated. Question three: Import java.util.map;import java.util.hashmap;import java.util.map.entry;public class  student {    public static void main (String[] args)  {         Map<Integer,Map <Integer,String>>  Classes = new hashmap<integer,map <integer,string>> ();         //Add Data         map<integer,string> student = null;         int num = 1;        for (int  i=1;i<=10;i++) {            student =  new HashMap<Integer,String> ();             classes.put (i,student);             for (int j=1;j<=50;j++) {                student.put (j , "Tom"  + num);                 num ++;            }         }                //using Entry        for (Entry<Integer,Map <integer,string>> class_entry : classes.entryset ()) {             map<integer,string> students = class_ Entry.getvalue ();             for (Entry<Integer, String> student_entry : students.entryset ()) {                 system.out.println ("Class:"  + class_entry.getkey (  +  "class, School Number:"  + student_entry.getkey ()  +  "No., Name:"  + student_ Entry.getvalue ());            }         }                 system.out.println ("--------------------------------------------------------------");                 //using Keyset        for ( Integer class_num:classes.keyset ()) {             map<integer,string> students = classes.get (Class_num);             for (Integer student_num:students.keyset ()) {                 system.out.println ("Class:"  + class_num +  "class, School Number:"  + student_num +  ", Name:"  +  Students.get (student_num));            }         }    }}


This article is from the "Forest Sensitive" blog, please be sure to keep this source http://senlinmin.blog.51cto.com/6400386/1782473

Big Data Java Foundation 12th day job

Related Article

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.