They are entirely different constructs. A HashMap
is an implementation of Map
. A Map maps keys to values. The key look up occurs using the hash.
On the other hand, a HashSet
is an implementation of Set
. A Set is designed to match the mathematical model of a set. A HashSet
does use a HashMap
to back its implementation, as you noted. However, it implements an entirely different interface.
When you are looking for what will be the best Collection
for your purposes, this Tutorial is a good starting place. If you truly want to know what’s going on, there’s a book for that, too.
Related Posts:
- HashSet vs. ArrayList
- How to sort a HashSet?
- What are the differences between a HashMap and a Hashtable in Java?
- When to use LinkedList over ArrayList in Java?
- Difference between Arrays.asList(array) and new ArrayList
(Arrays.asList(array)) - Initialization of an ArrayList in one line
- How to sort an ArrayList?
- Exception in thread “main” java.lang.StackOverflowError
- Iterate through a HashMap [duplicate]
- Iterate through a HashMap [duplicate]
- Why is there no SortedList in Java?
- What is the significance of load factor in HashMap?
- How to update a value, given a key in a hashmap?
- Collision resolution in Java HashMap
- Hashtable, HashMap, HashSet , hash table concept in Java collection framework
- Printing HashMap In Java
- Java Hashmap: How to get key from value?
- Sorting HashMap by values
- FIFO based Queue implementations?
- HashMap get/put complexity
- Create a List of primitive int?
- How to convert int[] to Integer[] in Java?
- Change priorityQueue to max priorityqueue
- Collections.emptyMap() vs new HashMap()
- “Cannot create generic array of ..” – how to create an Array of Map
? - Sort a Map
by values - How to calculate the intersection of two sets?
- Why is a ConcurrentModificationException thrown and how to debug it
- Union or intersection of Java Sets
- Map of maps – how to keep the inner maps as maps?
- toring and Retrieving ArrayList values from hashmap
- What are the -Xms and -Xmx parameters when starting JVM?
- How to match “any character” in regular expression?
- Cannot make a static reference to the non-static method fxn(int) from the type Two
- How to implement a tree data-structure in Java?
- Difference between StringBuilder and StringBuffer
- How to create a sub array from another array in Java?
- “Missing return statement” within if / for / while
- A JNI error has occurred, please check your installation and try again in Eclipse x86 Windows 8.1
- Round a double to 2 decimal places
- com.atomikos.icatch.SysException: Error in init: Log already in use? tmlog in ./
- @ converted to %40 in HTTPPost request
- Global variables in Java
- Java implementation for Min-Max Heap?
- How can I convert a long to int in Java?
- Generic Interface
- Java Method Stubs
- What’s the purpose of META-INF?
- JVM Crash – “EXCEPTION_ACCESS_VIOLATION”
- How to connect to FTP over TLS/SSL (FTPS) server in Java
- How to check type of variable in Java?
- Spring boot – Request method ‘POST’ not supported. Tried everything
- Convert .class to .java
- What does Scanner input = new Scanner(System.in) actually mean?
- unused import statement for used ones in IntelliJ IDEA
- Unsigned long in Java
- Integer range when using 64bit jdk
- Removing whitespace from strings in Java
- what is this ANT build?
- org.glassfish.jersey.servlet.ServletContainer ClassNotFoundException
- How to get the current working directory in Java?
- What is a safe way to create a Temp file in Java?
- org.apache.jasper.JasperException: Unable to compile class for JSP:
- How do I parse command line arguments in Java?
- Missing method body, or declare abstract in Java
- java code is showing error. ( ‘;’,expected)
- Efficient swapping of elements of an array in Java
- local variables referenced from an inner class must be final or effectively final
- java.lang.NumberFormatException: empty String
- Java and Windows – error: illegal escape character
- How should I copy Strings in Java?
- Bank Account Java Program
- List of all special characters that need to be escaped in a regex
- No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
- java.lang.ArithmeticException: / by zero
- ReferenceError: “alert” is not defined
- How to write an ArrayList of Strings into a text file?
- how to fix Cannot call sendRedirect() after the response has been committed?
- Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project
- difference between equals() and hashCode()
- Adding days to a date in Java
- The C# Shorthand getters and setters
- What’s the reason I can’t create generic array types in Java?
- Jackson with JSON: Unrecognized field, not marked as ignorable
- Create a two dimensional string array anArray[2][2]
- Convert double to Int, rounded down
- A beginner’s error (args[0]) [duplicate]
- Converting from byte to int in Java
- When/why to call System.out.flush() in Java
- Throwing multiple exceptions in Java
- fixing errors on a program to call methods in java
- How to Set the Background Color of a JButton on the Mac OS
- how to use drawArc()
- How to add RGB values into setColor() in Java?
- Can you write virtual functions / methods in Java?
- Creating video player using Java
- Can I override and overload static methods in Java?
- How can i fix this equals on primitive type(int)
- Split string into array of character strings
- intellij idea – Error: java: invalid source release 1.9