answersLogoWhite

0


Best Answer

The only difference is that the LinkedHashSet maintains the order of the items added to the Set. It does this by maintaining a doubly linked list containing the hash and the original order of the items. According to Sun, the LinkedHashSet should run nearly as fast as the HashSet.

LinkedHashSet A LinkedHashSet is an ordered version of HashSet that

maintains a doubly-linked List across all elements. Use this class instead of HashSet

when you care about the iteration order. When you iterate through a HashSet the

order is unpredictable, while a LinkedHashSet lets you iterate through the elements

in the order in which they were inserted.

HashSet A HashSet is an unsorted, unordered Set. It uses the hashcode

of the object being inserted, so the more efficient your hashCode() implementation

the better access performance you'll get. Use this class when you want a collection

with no duplicates and you don't care about order when you iterate through it.

User Avatar

Wiki User

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

Wiki User

13y ago

HashSet

A HashSet is an unsorted, unordered Set. It uses the hashcode of the object being inserted, so the more efficient your hashCode() implementation the better access performance you'll get. Use this class when you want a collection with no duplicates and you don't care about order when you iterate through it.

LinkedHashSet

A LinkedHashSet is an ordered version of HashSet that maintains a doubly-linked List across all elements. Use this class instead of HashSet when you care about the iteration order. When you iterate through a HashSet the order is unpredictable, while a LinkedHashSet lets you iterate through the elements in the order in which they were inserted.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Difference between HashSet and Linkedhash set in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the difference between a treeset and hashset in Java?

The difference between these two sets is simply the order/algorithm in which items are added to/accessed/removed from the map. The circumstances determine which particular implementation is better/faster. A treeSet organizes data in a tree through use of Comparator (natural ordering) and the hashSet organizes data in a hash table (using a hash function). See the Java API for more info: http://www.j2ee.me/javase/6/docs/api/java/util/TreeSet.html http://java.sun.com/javase/6/docs/api/java/util/HashSet.html The previous answer (unless I'm mistaken) is pretty much completely wrong... ----------- Previous Answer --------- In a treeset data are placed in order... while in a hashset data is randomly placed... A treeset is more efficient in case of search element. As hashSet use the hash function to store the values, it does not maintain the order of elements, but TreeSet maintains the natural odering of elements (you don't need to sort it).


What is the main difference between UNIX and JAVA?

Unix is an operating system, Java is a language.


Difference between recordset and resultset in java?

Rowset


WAP to show the difference between a variable and static variable?

difference between constant and static variables in java


What is Difference between java and core java?

Java or Java SE comes with the standard library, with all the crazy classes to make life easy. Java Core does not come with most of these classes, so that it is a lot smaller.

Related questions

What is the difference between a treeset and hashset in Java?

The difference between these two sets is simply the order/algorithm in which items are added to/accessed/removed from the map. The circumstances determine which particular implementation is better/faster. A treeSet organizes data in a tree through use of Comparator (natural ordering) and the hashSet organizes data in a hash table (using a hash function). See the Java API for more info: http://www.j2ee.me/javase/6/docs/api/java/util/TreeSet.html http://java.sun.com/javase/6/docs/api/java/util/HashSet.html The previous answer (unless I'm mistaken) is pretty much completely wrong... ----------- Previous Answer --------- In a treeset data are placed in order... while in a hashset data is randomly placed... A treeset is more efficient in case of search element. As hashSet use the hash function to store the values, it does not maintain the order of elements, but TreeSet maintains the natural odering of elements (you don't need to sort it).


What is difference between java 2 and java 5?

They are different versions. Java 5 is newer than Java 2. Think of it like the difference between the Playstation 1 and the Playstation 3.


Major difference between c and java?

Java is object oriented, C is not...


What is the difference between connectivity in java?

kamina


What is difference between connectivity in java?

kamina


What is the main difference between UNIX and JAVA?

Unix is an operating system, Java is a language.


Difference between recordset and resultset in java?

Rowset


What is the difference between JAD and JAR?

JAD-Java Application Description JAR-Java archive


What is hashing in Java?

Creating a Integer out of an object is called hashing. Hashing is commonly used in HashTable, HashMaps and HashSet. For instance you have Alex John Peter Hashing on each value would generate something like 123455 Alex 123344 John 123987 Peter when put in hashtable or hashset would be quicker to find each piece of information. There are many algorithms available with java to get the hash of an object.


What is the difference between java and object oriented programming?

java is a programming language/platform that embodies object oriented programming concepts. The question of what is the difference is like asking what is the difference between cars and a Volvo.


What is the difference between c plus plus and java programming?

Java doesn't have pointers. C++ has pointers.


What difference between InputStreamReader and DatainputStream in java?

Both are same