Hashmap

Status
Nicht offen für weitere Antworten.

The_S

Top Contributor
Nachdem ich öffters mal den Begriff "Hasmap" gehört habe und ich mir nur geringfügig etwas darunter vorstellen kann, wollte ich darüber mal "ein paar Informationen sammeln".

Was ist genau eine Hashmap? Was kann ich mit ihr anstellen, wofür wird sie normalerweiße gebraucht? Was gibts sonst noch zu Hashmaps zu sagen?
 

Sky

Top Contributor
Die API zu HashMap hat gesagt.:
Hash table based implementation of the Map interface. This implementation provides all of the optional map operations, and permits null values and the null key. (The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.) This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.

This implementation provides constant-time performance for the basic operations (get and put), assuming the hash function disperses the elements properly among the buckets. Iteration over collection views requires time proportional to the "capacity" of the HashMap instance (the number of buckets) plus its size (the number of key-value mappings). Thus, it's very important not to set the initial capacity too high (or the load factor too low) if iteration performance is important.

An instance of HashMap has two parameters that affect its performance: initial capacity and load factor. The capacity is the number of buckets in the hash table, and the initial capacity is simply the capacity at the time the hash table is created. The load factor is a measure of how full the hash table is allowed to get before its capacity is automatically increased. When the number of entries in the hash table exceeds the product of the load factor and the current capacity, the capacity is roughly doubled by calling the rehash method.

As a general rule, the default load factor (.75) offers a good tradeoff between time and space costs. Higher values decrease the space overhead but increase the lookup cost (reflected in most of the operations of the HashMap class, including get and put). The expected number of entries in the map and its load factor should be taken into account when setting its initial capacity, so as to minimize the number of rehash operations. If the initial capacity is greater than the maximum number of entries divided by the load factor, no rehash operations will ever occur.

If many mappings are to be stored in a HashMap instance, creating it with a sufficiently large capacity will allow the mappings to be stored more efficiently than letting it perform automatic rehashing as needed to grow the table.

Note that this implementation is not synchronized. If multiple threads access this map concurrently, and at least one of the threads modifies the map structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more mappings; merely changing the value associated with a key that an instance already contains is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the map. If no such object exists, the map should be "wrapped" using the Collections.synchronizedMap method. This is best done at creation time, to prevent accidental unsynchronized access to the map:

Map m = Collections.synchronizedMap(new HashMap(...));
The iterators returned by all of this class's "collection view methods" are fail-fast: if the map is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove or add methods, the iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.

Note that the fail-fast behavior of an iterator cannot be guaranteed as it is, generally speaking, impossible to make any hard guarantees in the presence of unsynchronized concurrent modification. Fail-fast iterators throw ConcurrentModificationException on a best-effort basis. Therefore, it would be wrong to write a program that depended on this exception for its correctness: the fail-fast behavior of iterators should be used only to detect bugs.
 

The_S

Top Contributor
Und auf Deutsch? Ich tu mir schwer bei Sachen von denen ich wirklich NULL also nicht mal ansatzweiße ne Ahnung hab! Aber trotzdem schonmal Danke!
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
krgewb remove beim Iterieren einer HashMap Java Basics - Anfänger-Themen 3
F Java Object to Hashmap ? Java Basics - Anfänger-Themen 6
S HashMap mehrere Keys zu einem Value Java Basics - Anfänger-Themen 3
A Daten aus einer HashMap aus einer DB speichern und mit neuen Werten vergleichen Java Basics - Anfänger-Themen 8
T HashMap Lsite gibt die sachen nicht aus wie gewollt. Java Basics - Anfänger-Themen 3
krgewb HashMap Java Basics - Anfänger-Themen 2
B Hashmap richtig bauen, die Tripel auf Zahl abbildet? Java Basics - Anfänger-Themen 10
"java.util.HashMap.get(Object)" is null Java Basics - Anfänger-Themen 10
berserkerdq2 Hashmap, wie prüfe ich ob ein Key schon existiert Java Basics - Anfänger-Themen 19
S Durch HashMap iterieren Java Basics - Anfänger-Themen 8
rafi072001 Sortieren einer HashMap nach Values Java Basics - Anfänger-Themen 2
F gson mit einer Hashmap Java Basics - Anfänger-Themen 2
J JSON-HashMap Java Basics - Anfänger-Themen 3
J Hashmap Java Basics - Anfänger-Themen 13
C Hashmap zickt Java Basics - Anfänger-Themen 9
S HashMap contains() Methode Java Basics - Anfänger-Themen 1
Z Satz aufteilen und die Wörter zählen (HashMap) Java Basics - Anfänger-Themen 15
N enum Attribut von Objekten einer Hashmap ausgeben Java Basics - Anfänger-Themen 6
P Verschachtelte Hashmap Java Basics - Anfänger-Themen 6
I Sortiert eine HashMap nicht gleich wie eine ArrayList? Java Basics - Anfänger-Themen 1
B HashMap alphabetisch sortieren Java Basics - Anfänger-Themen 2
J HashMap Java Basics - Anfänger-Themen 6
M Enum-Variable HashMap zuweisen Java Basics - Anfänger-Themen 5
U Hashmap Iterator selbst implementieren Java Basics - Anfänger-Themen 10
N HashMap in List good practice? Java Basics - Anfänger-Themen 2
K Value eines HashMaps in einer HashMap wiedergeben. Java Basics - Anfänger-Themen 5
O Hashmap, ArrayList, LinkedList Java Basics - Anfänger-Themen 7
O HashMap - ArrayList Java Basics - Anfänger-Themen 29
J Hashmap langsamer als compareTo? Java Basics - Anfänger-Themen 23
E HashMap+Vererbung Java Basics - Anfänger-Themen 11
J Erhöhen eines Values als Integer bei gleichen Keys in HashMap Java Basics - Anfänger-Themen 12
N Methoden HashMap interne Werte miteinander vergleichen Java Basics - Anfänger-Themen 7
W The type Long is not visible HashMap Java Basics - Anfänger-Themen 4
M Objekt mit Hashmap vergleichen Java Basics - Anfänger-Themen 22
S Gibt es für die Klasse HashMap Generic Implementierungen? Java Basics - Anfänger-Themen 11
C HashMap - alle keys haben values der letzten put-Anweisung Java Basics - Anfänger-Themen 3
J Hashmap auslesen Java Basics - Anfänger-Themen 7
F HashMap sortieren <String, Long> Java Basics - Anfänger-Themen 3
GreenTeaYT HashMap dupliziert meine Elemente? Java Basics - Anfänger-Themen 2
shiroX Methoden Morse-Code Übersetzer mit HashMap Java Basics - Anfänger-Themen 5
E HashMap Problem Java Basics - Anfänger-Themen 5
P Hashmap anstatt LinkedList? Java Basics - Anfänger-Themen 6
T HashMap und die Methoden Java Basics - Anfänger-Themen 13
N Methoden Interaktives PDF mit HashMap befüllen Java Basics - Anfänger-Themen 0
Z Hashmap auseinandernehmen und analysieren Java Basics - Anfänger-Themen 7
B Durchlaufen von Hashmap und Arraylist Java Basics - Anfänger-Themen 8
F HashMap oder welches Array? Java Basics - Anfänger-Themen 4
T HashMap Java Basics - Anfänger-Themen 24
L Hashmap mit variablem Key Java Basics - Anfänger-Themen 9
M Collections Probleme mit Hashmap Java Basics - Anfänger-Themen 4
N Collections String in HashMap umwandeln Java Basics - Anfänger-Themen 3
Z HashMap richtig benutzen Java Basics - Anfänger-Themen 2
lgund HashMap // TS3 Query Java Basics - Anfänger-Themen 7
Z Hashmap Iterator löscht nicht Java Basics - Anfänger-Themen 8
E Hashmap Wert auslesen Java Basics - Anfänger-Themen 2
S Printstream für einen Hashmap Loop Java Basics - Anfänger-Themen 1
dat_vin OOP Hashmap und Attribute Java Basics - Anfänger-Themen 7
C Check ob eine HashMap schon existiert Java Basics - Anfänger-Themen 16
G Vererbung Eigene HashMap Variante Java Basics - Anfänger-Themen 2
R Hashmap in anderer Klasse nicht benutzbar Java Basics - Anfänger-Themen 1
T Java Hashmap Java Basics - Anfänger-Themen 3
L Gibt es etwas wie "HashMap <String, String, String> Java Basics - Anfänger-Themen 9
K HashMap mit Daten aus ArrayList befüllen Java Basics - Anfänger-Themen 14
S OOP Klasse mit static-Eigenschaften - HashMap füllen Java Basics - Anfänger-Themen 6
O HashMap Fragen Java Basics - Anfänger-Themen 8
T HashMap Werte einfügen, durchsuchen und auslesen Java Basics - Anfänger-Themen 17
M Semantisches Problem HashMap/Netzwerk Java Basics - Anfänger-Themen 4
D HashMap Keys durchlaufen Java Basics - Anfänger-Themen 2
B Zugriff auf csv-Datei per hashmap Java Basics - Anfänger-Themen 5
M HashMap keys ausgeben Java Basics - Anfänger-Themen 2
S In einer Hashmap Klassen regestrieren Java Basics - Anfänger-Themen 2
H Collections Was ist schneller - HashMap + Sort v TreeMap? Java Basics - Anfänger-Themen 75
F HashMap nach kleinstem Value durchsuchen Java Basics - Anfänger-Themen 11
G HashMap Java Basics - Anfänger-Themen 6
F Wortpaare - HashMap - ArrayList Java Basics - Anfänger-Themen 6
M HashMap Frage Java Basics - Anfänger-Themen 3
M HashMap - put() reagiert nicht? Java Basics - Anfänger-Themen 8
N Cast eines Objektes in eine Hashmap Java Basics - Anfänger-Themen 13
A CSV Zeilenweise einlesen und in einer HashMap speichern Java Basics - Anfänger-Themen 12
A Input/Output Hashmap in einem JPanel via JList anzeigen Java Basics - Anfänger-Themen 8
K HashMap auf leere Key-Value-Paare prüfen Java Basics - Anfänger-Themen 14
F Hilfe bei der HashMap. Java Basics - Anfänger-Themen 3
F HashMap vs. TreeMap Java Basics - Anfänger-Themen 5
B HashMap Java Basics - Anfänger-Themen 9
C Collections String[] als value in HashMap Java Basics - Anfänger-Themen 6
V Hashmap Iterieren Java Basics - Anfänger-Themen 4
C Csv File in Hashmap ausgeben Java Basics - Anfänger-Themen 14
T HashMap<String,Object> Werte auslesen Java Basics - Anfänger-Themen 5
I HashMap sortieren Java Basics - Anfänger-Themen 10
I HashMap Java Basics - Anfänger-Themen 11
H Collections Brauche modifizierte HashMap Java Basics - Anfänger-Themen 6
H TreeMap/HashMap synchronisieren Java Basics - Anfänger-Themen 2
A Datentypen Hashmap to Array Java Basics - Anfänger-Themen 11
D HashMap überschreibt Werte Java Basics - Anfänger-Themen 7
pg1337 Interface Comparable-Interface bei HashMap Java Basics - Anfänger-Themen 21
D erweiterte hashmap Java Basics - Anfänger-Themen 5
H HashMap<Int, String> - Er findet die Int-Klasse nicht. Java Basics - Anfänger-Themen 3
L HashMap zu JList Java Basics - Anfänger-Themen 6
S Erste Schritte HashMap Kurze Frage - Werte über Schleife ausgeben Java Basics - Anfänger-Themen 30
F Collections ArrayList oder Hashmap mittel Collections.sychronised Java Basics - Anfänger-Themen 6

Ähnliche Java Themen


Oben