answersLogoWhite

0


Best Answer

A linked list is made up of a sequence of connected (linked) nodes. A hashtable is usually backed by an array, and is an association of keys and values. When an object is added to the array it becomes a value; the object is hashed to get a key (an index into the array).

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

While these two data structures are nearly identical in Java, there are a few distinguishing features. The main two are that a HashMap is not synchronized (Hashtable is thread-safe) and that HashMap allows keys and values to be null (Hashtable will throw an Exception if you attempt to add a null key or value).

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the difference between LinkedList and Hashtable?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Difference between hashtable and hashmap in java?

1) hashtable is synchronized , hashmap is not 2) hashtable is slow , hashmap is fast 3) hashtable is old and hashmap is new


Which all represent the properties of hashtable in java?

HashTableLike Vector, Hashtable has existed from prehistoric Java times. For fun, don't forget to note the naming inconsistency: HashMap vs. Hashtable. Where's the capitalization of t? Oh well, you won't be expected to spell it. Anyway, just as Vector is a synchronized counterpart to the sleeker, more modern ArrayList, Hashtable is the synchronized counterpart to HashMap. Remember that you don't synchronize a class, so when we say that Vector and Hashtable are synchronized, we just mean that the key methods of the class are synchronized. Another difference, though, is that while HashMap lets you have null values as well as one null key, a Hashtable doesn't let you have anything that's null.


What is the difference between hashtable and Dictionary?

Dictionary is typed (sо valuetypes dоn't need bоxing), a Hashtable isn't (sо valuetypes need bоxing). Hashtable has a nicer way оf оbtaining a value than dictionary IMHО, because it always knоws the value is an оbject. Thоugh if yоu're using .NET 3.5, it's easy tо write an extensiоn methоd fоr dictionary tо get similar behaviоr.The Hashtable class is a specific type оf dictionary class that uses an integer value (called a hash) tо aid in the stоrage оf its keys. The Hashtable class uses the hash tо speed up the searching fоr a specific key in the cоllectiоn. Every оbject in .NET derives frоm the Оbject class. This class suppоrts the GetHash methоd, which returns an integer that uniquely identifies the оbject. The Hashtable class is a very efficient cоllectiоn in general. The оnly issue with the Hashtable class is that it requires a bit оf оverhead, and fоr small cоllectiоns (fewer than ten elements) the оverhead can impede perfоrmance.There is оne mоre impоrtant difference between a HashTable and Dictionary. If yоu use indexers tо get a value оut оf a HashTable, the HashTable will successfully return null fоr a nоn-existent item, whereas the Dictionary will thrоw an errоr if yоu try accessing a item using a indexer which dоes nоt exist in the Dictionary.The HashTable is the base class that is weakly typed; the DictionaryBase abstract class is strоnly typed and uses internally a HashTable.A strange thing noticed abоut Dictionary is, when we add the multiple entries in Dictionary, the оrder in which the entries are added is maintained. Thus if you apply a fоreach оn the Dictionary, you will get the recоrds in the same оrder you have inserted them. Whereas, this is nоt true with nоrmal HashTable, when you add same recоrds in Hashtable the оrder is nоt maintained. If 'Dictionary is based оn Hashtable' is true, why Dictionary maintains the оrder but HashTable dоes nоt?As tо why they behave differently, it's because Generic Dictionary implements a hashtable, but is nоt based оn System.Cоllectiоns.Hashtable. The Generic Dictionary implementatiоn is based оn allоcating key-value-pairs frоm a list. These are then indexed with the hashtable buckets fоr randоm access, but when it returns an enumeratоr, it just walks the list in sequential оrder - which will be the оrder оf insertiоn as lоng as entries are nоt re-used.


What do you mean by pointer in linked list?

A pointer is a memory reference to a data structure. So when you allocate memory for your list elements, they will be stored at some address X in your system memory. A pointer is simply a variable that contains that address X. You can access the memory that a pointer points to by dereferrencing it with the * operator.Ex:int main(){LinkedList *x; /* Declare a pointer to a linked list (a type which you would have to define using "struct" or "class") */x = new LinkedList(); /* Here we create (aka "instantiate") a LinkedList object and allocate memory for it, x now contains (points to) the memory address of our LinkedList object */// You can now access any LinkedList members through x, for example x->next might point you to the next element of your LinkedList


If you put different values in hashtable in which order does it display the output?

Assuming you're using the Hashtable.toString() method, output order depends on the order of the backend storage. The array of Entry objects (the "table" array) seems to actually be read backwards by the Hashtable iterator. The order of elements in the table array, of course, depends on how the hash function for the keys of the Hashtable works.


What is difference between ArrayList and LinkedList?

Both ArrayList and LinkedList are used to store and manipulate data items, but they have different properties associated with them. In ArrayList, the data items are stored at contiguous locations ( memory locations adjacent to each other ), while in LinkedList, elements are stored in noncontiguous memory locations.ArrayList uses an array of data structures for its implementation, while a LinkedList uses a doubly linked list data structure. The doubly linked list is a linear data structure where the elements are not stored separately but are stored as part of the node. A node is an object with two parts, the data-storing part and the address-storing part. The data storing part stores the data, while the address part holds the references of the next node and the previous node in the list. Due to this, random access to elements takes a lot of time compared to ArrayList because ArrayList stores the index of elements since they are stored in a contiguous memory location. The random access to an element takes O(1) time in ArrayList while O(n) time in a LinkedList. Another important difference between the two classes are is that in ArrayList, the time taken to manipulate data items is very large compared to LinkedList.This is so because ArrayList is implemented through the array structure, so whenever we want to delete a data item or shift a data item internally, the whole array has to be traversed to shift the memory bits as it happens in arrays. While in LinkedList, there is no concept or need for shifting of memory bits; hence, operations such as deletion or adding an element in the middle of the list, etc., happen at a much faster rate than it happens in ArrayList.The insertion and deletion of an element take O(n) time in ArrayList while O(1) time in a LinkedList. The memory allocation to the ArrayList is done at compile time, while the memory allocation to LinkedList is done at run time. The memory required in LinkedList is also more than in ArrayList.This is because, along with the data items that need to be stored, the LinkedList needs extra memory for storing the addresses of the next and previous node. Since the deletion and insertion operations are very efficiently done in LinkedList, they are preferred over ArrayList, where insertion and deletion are done to data frequently.ArrayList is preferred when data is not being modified often, but random access to data is needed.


Can you name the legacy classes and interface for collections?

Dictionary, Hashtable ,Properties ,Stack and vector are the legacy classes in java


What are the methods of hash table?

See the related link below for the Java API documentation for the Hashtable class and its methods.


What is the difference between primitive and non primitive data structure?

A primitive data structure is generally a basic structure that is usually built into the language, such as an integer, an array or a linked-list.A non-primitive data structure is built out of primitive data structures linked together in meaningful ways, such as a binary search tree, AVL Tree, Hashtable, etc.


Hash table in java?

HashMapThe HashMap gives you an unsorted, unordered Map. When you need a Map and you don't care about the order (when you iterate through it), then HashMap is the way to go; the other maps add a little more overhead. Where the keys land in the Map is based on the key's hashcode, so, like HashSet, the more efficient your hashCode() implementation, the better access performance you'll get. HashMap allows one null key and multiple null values in a collection.HashTableLike Vector, Hashtable has existed from prehistoric Java times. For fun, don't forget to note the naming inconsistency: HashMap vs. Hashtable. Where's the capitalization of t? Oh well, you won't be expected to spell it. Anyway, just as Vector is a synchronized counterpart to the sleeker, more modern ArrayList, Hashtable is the synchronized counterpart to HashMap. Remember that you don't synchronize a class, so when we say that Vector and Hashtable are synchronized, we just mean that the key methods of the class are synchronized. Another difference, though, is that while HashMap lets you have null values as well as one null key, a Hashtable doesn't let you have anything that's null.


What difference LinkedList and ArrayList?

public class ArrayList public class LinkedList extends AbstractList extends AbstractSequentialList implements List, RandomAccess, Cloneable, Serializableimplements List, Cloneable, Serializable Resizable-array implementation of the List interface.Linked list implementation of the List interface Implements all optional list operations, and permits all elements, including null. Implements all optional list operations, and permits all elements (including null).


Benefit of inner class in java?

Inner classes are very useful for classes that are written specifically to be used with the encompassing class. A good example of this would be a LinkedListNode class being part of a LinkedList class: public class LinkedList { private LinkedListNode root; private class LinkedListNode { private Object data; private LinkedListNode nextNode; } } No class except your LinkedList class needs to know anything about the LinkedListNode class. So we hide it so no one else needs to worry about what it does.