1. Describe the HASHMAP internal implementation principle.
HashMap is K-v, K is the only one that does not repeat.
In the storage mode, a hashing algorithm is implemented hashmap the bottom layer, and the hash is a search algorithm based on keyword, which improves the HASHMAP's searching speed. HashMap's lookup mechanism is to first use the object's hashcode to derive an address with equals to compare the various elements of the list in the address, if the same, take out the corresponding value values.
2. Describe the difference between hashset and HashMap.
The Hashset:hashset collection is implemented internally through HASHMAP, using the key part of HashMap. Implement the set interface, set inherits the 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.
Import Java.util.HashMap;
Import Java.util.Map;
Import Java.util.Map.Entry;
/**
* The collection of grades uses a nested implementation of map. Class 10, 50 people per class.
*
* @author Admin
*
*/
public class Map_ nested loop Job 1 {
public static void Main (string[] args) {
Create class number
Map<integer, map<string, string>> classes = new Hashmap<integer, map<string, string>> ();
Create a collection of class lists
map<string, string> names = null;
int no = 1;
for (int i = 1; i <=; i++) {
names = new hashmap<string, string> ();
Classes.put (i, names);//Put the class list in the class number collection
for (int j = 1; J <=; J + +) {
Names.put ("study number" + J, "Marry" + No);
no++;
}
}
Reading map Nesting Loops
For (Entry<integer, map<string, string>> Entry:classes.entrySet ()) {
Integer key = Entry.getkey ();
map<string, string> values = Entry.getvalue ();
For (entry<string, string> entry0:values.entrySet ()) {
Take the school number
String classnum = Entry0.getkey ();
Take a name
String NameSet = Entry0.getvalue ();
SYSTEM.OUT.PRINTLN (Key + "." + Classnum + "," + nameset);
}
}
}
}
4. Programming to achieve copy of text files. The reasonable design procedure, obtains the buffer area the size high efficiency interval.
The prompt buffer setting starts at 1k and does not exceed 10M.
/**
* 4. Programming to achieve copy of text files. The reasonable design procedure, obtains the buffer area the size high efficiency interval. The prompt buffer setting starts at 1k and does not exceed 10M.
*
* @author Admin
*
*/
public class Copy_ Job {
public static void Main (string[] args) {
Get System Properties
String str = system.getproperty ("Line.separator");
System.out.println (str);
String srcfile = "D:/aa.txt";
String tarfile = "D:/bb.txt";
FileReader reader = null;
FileWriter writer = null;
try {
Reader reading src file
reader = new FileReader (srcfile);
FileWriter written to tar file
writer = new FileWriter (Tarfile, false);
Defining character buffers
char[] buf = new char[1024];
int len = 0;
while (len = Reader.read (BUF))! =-1) {
Writer.write (buf, 0, Len);
}
System.out.println ("over");
} catch (Exception e) {
E.printstacktrace ();
} finally {
try {
if (reader! = null) {
Reader.close ();
}
if (writer! = null) {
Writer.close ();
}
} catch (Exception E2) {
}
}
}
}
Java Foundation 12th Day _ Collection