can some one tell me the difference between hash tables and linked list please. I am very confused
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
can some one tell me the difference between hash tables and linked list please. I am very confused
Welcome to the Forum! Please read this topic to learn how to post code correctly and other useful tips for newcomers.
And please don't post topics requesting help in the Member Introductions area. I moved the thread to a more appropriate sub-forum.
At conceptual level (not strictly related to Java):
A linked list is a data structure composed by N nodes where each node has a "pointer" to the next node (the last node has a "null" next). So there is a chain of nodes and you need to keep a pointer to the "head" of the list. If you want to find the n-th node, you have to scan the list node by node. Note that there is also the concept of "double" linked list. Here a node has 2 pointers: to the previous and to the next node.
An hash table has a more complex structure. Firstly it has a list (generally an indexable list or array, never a "linked" list) that is known as the "buckets" list. Each bucket is a sort of container for more elements that share the same feature (in Java this "feature" is based on the hashCode() ). The main goal is to distribute elements among the buckets in an quite even way. Think to a big encyclopedia you can have at home, where each volume groups all words with the same initial. All words are distributed quite evenly. And you are very close to this.
Under a "bucket" there is generally a linked list where each item has a key and a value. Once you find the right bucket, you need to scan this linked list to find the value by the key.
Andrea, www.andbin.net — SCJP 5 (91%) – SCWCD 5 (94%)
Useful links for Java beginners – My new project Java Examples on Google Code