aspose file tools*
The moose likes Java in General and the fly likes Java Collections - Internal Working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java Collections - Internal Working" Watch "Java Collections - Internal Working" New topic
Author

Java Collections - Internal Working

Ak Rahul
Greenhorn

Joined: Jul 08, 2009
Posts: 21
Can anyone let me know how the java collections work internally?

For example, how do the collections LinkedList, ArrayList, HashMap, LinkedHashMap, HashSet, LinkedHashSet work?

Does the LinkedList, LinkedHashMap, LinkedHashSet have a single linked list or double linked list internally?

How does hashing work internally in HashMap, LinkedHashMap, HashSet, LinkedHashSet?

The more details the better for me. If you can explain me or direct me to material that explains this, then I shall be really grateful.

Thanks.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10255
    
    8

R Ak wrote:

Please check your private messages for an important administrative matter


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10255
    
    8

Have you installed the JDK on your machine.
Look for a file called src.zip in the JDK installation directory. That contains the source code for the Java classes. It should give you a clear picture about the implementation.
Ak Rahul
Greenhorn

Joined: Jul 08, 2009
Posts: 21
thanks maneesh. Can you direct me to some text that explains this, instead of reading the JDK source code, since I also want to know which one has better performance, etc.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14108
    
  16

See The Collections Framework, which contains links to several other pages including a Design FAQ.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ulrika Tingle
Ranch Hand

Joined: Nov 24, 2009
Posts: 92
Rahul Ak wrote:thanks maneesh. Can you direct me to some text that explains this, instead of reading the JDK source code, since I also want to know which one has better performance, etc.


What you need is a general knowledge of the basic standard data structures such as arrays, list, trees and hash tables.

Then you need to look at the Sun API specification to find out the exact properties of a specific collection. It's usually detailed enougth to know what to expect. And by relying on this information only your code becomes implementation independent. This is because the API specifications from Sun work as a standard for the Java language. Trying to "envision" the properties of a collection by seccondguessing its internal workings or looking at an implementation will lead you wrong.
Ak Rahul
Greenhorn

Joined: Jul 08, 2009
Posts: 21
Thank you for all responses. I really appreciate your help.


regards,
Rahul
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Collections - Internal Working