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