+ 1

Can anyone explain the collection and Hashmap in java !?

I'm really confused of these topics !?

19th Jul 2018, 6:06 PM
Bharathi Priya
Bharathi Priya - avatar
2 Respostas
+ 1
https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html HashMap is essentially a number of 'buckets' which represent a hash. Each bucket is like a linked list. When you read from the map it uses the hash to find which bucket to look in. Any hash collisions can be resolved by looking through the linked list. It's very performant and is probably the one you should default to unless you have a good reason to use another one (especially in the beginning when you're learning). https://www.tutorialspoint.com/java/java_collections.htm A collection is simply something that holds a reference to a number of other objects, implementing the Collection interface. Think Lists, Sets, Queue etc. It is iterable, which means you can use it in an enhanced for loop. Please add if you have further questions as it's quite broad now :p
19th Jul 2018, 9:20 PM
Dan Walker
Dan Walker - avatar
0
The Java collections framework (JCF) is a set of classes and interfaces that implement commonly reusable collection data structures. Although referred to as a framework, it works in a manner of a library. The JCF provides both interfaces that define various collections and classes that implement them. Simply put, the HashMap stores values by key and provides APIs for adding, retrieving and manipulating stored data in various ways. The implementation is based on the the principles of a hashtable, which sounds a little complex at first but is actually very easy to understand. Key-value pairs are stored in what is known as buckets which together make up what is called a table, which is actually an internal array. Once we know the key under which an object is stored or is to be stored, storage and retrieval operations occur in constant time, O(1) in a well-dimensioned hash map. To understand how hash maps work under the hood, one needs to understand the storage and retrieval mechanism employed by the HashMap. We’ll focus a lot on these. Finally, HashMap related questions are quite common in interviews, so this is a solid way to either prepare an interview or prepare for it. http://net-informations.com/java/col/hashmap.htm
4th Sep 2018, 5:34 AM
rahul kumar
rahul kumar - avatar