dir.by  
Поиск >>

Компьютер, программы
→
Java
→
Java (class, interface, collections, etc.)
 Collections in Java 
посмотрели 2428 раз
обновлено: 30 September 2026
Collections are lists, queues, dictionaries, and other classes for adding, removing, and sorting items.

All collections are defined in the java.util.* package

When creating a collection, the <E> type is used, which means that all elements are of the same type.
Since the collection uses the <E> type when it is created, so the collection is called generic (or in other words, typed).
 
Java Collections
 
Java Collections based on interface List<E> (This is an array, i.e. add and remove elements, get an element by index)
  Java  
class ArrayList<E>
class ArrayList<E> is an array (in other words, a collection of elements).
Any element can be gotten by integer index.
You can add and delete elements.
Is not synchronized (not thread-safe).
Read more class ArrayList<E> ...
synchronized for threads
❌
  Java  
class Vector<E>
class Vector<E> is an array (in other words, a collection of elements).
Any element can be gotten by integer index.
You can add and delete elements.
Vector is fully synchronized (thread-safe).
Note! Vector is the same as ArrayList, and the difference is that Vector is fully synchronized (thread-safe). Vector is slower than ArrayList.
Read more class Vector<E> ...
synchronized for threads
✅
  Java  
class Stack<E>
class Stack<E> extends class Vector<E> with the "last in - first out" algorithm:
Each new element is placed at the very top.
The first element is the one at the very top.
Stack is fully synchronized (thread-safe).
Read more class Stack<E> ...
synchronized for threads
✅
  Java  
class CopyOnWriteArrayList<E>
CopyOnWriteArrayList it is the same as ArrayList but safe in threads.
In CopyOnWriteArrayList all mutative operations (add, set, and so on) are implemented by making a fresh copy of the underlying array.
Read more class CopyOnWriteArrayList<E> ...
synchronized for threads
✅
 
Java Collections based on interface Queue<E> (queue, i.e. adding, deleting elements according to the algorithm: first in - first out)
Java
class PriorityQueue<E>
 
Java Collections based on interface Deque<E> (two-way queue i.e. adding, removing elements from the beginning and end)
  Java  
class LinkedList<E>
class LinkedList is a set of Nodes. Each Node has 2 links: a link to the next Node and a link to the previous Node.
In LinkedList can add and remove elements.
LinkedList is not synchronized.
Read more class LinkedList<E> ...
synchronized for threads
❌
Java
class ArrayDeque<E>
Java
class LinkedBlockingDeque<E>
Java
class ConcurrentLinkedDeque<E>
 
Java Collections based on interface Set<E> (collection of unique elements)
  Java  
class HashSet<E>
HashSet contains a non-repeating collection of items.
HashSet contains unsorted items.
HashSet allows you to quickly determine whether such an element exists or not (fast because the hash code of the element is calculated).
Read more class HashSet<E> ...
synchronized for threads
❌
LinkedHashSet implementation the same as HashSet and additionally maintains a doubly-linked list running through all of its elements. This linked list makes guarantees order of items in the set.
class LinkedHashSet<E> is not synchronized.
 
Java Collections based on interface SortedSet<E> (Collection of unique elements. Items are stored in a sorted view)
Java
class TreeSet<E>
TreeSet contains a non-repeating collection of items.
TreeSet Items are stored in a sorted form.[/rus]
TreeSet   oracle.com ...
Java
class ConcurrentSkipListSet<E>
 
Java Collections based on interface Map<K, V> (contains keys and values. Each key is associated with only one value, i.e. from the key we get the value )
Java
class HashMap<K,V>
Java
class Hashtable<K,V>
Hashtable   oracle.com ...

There are several differences between Hashtable and HashMap in Java:

Hashtable is synchronized, whereas HashMap is not. This makes HashMap better for non-threaded applications, as unsynchronized Objects typically perform better than synchronized ones.

Hashtable does not allow null keys or values. HashMap allows one null key and any number of null values.

One of HashMap subclasses is LinkedHashMap, so in the event that you'd want predictable iteration order (which is insertion order by default), you could easily swap out the HashMap for a LinkedHashMap. This wouldn't be as easy if you were using Hashtable.

Since synchronization is not an issue for you, I'd recommend HashMap. If synchronization becomes an issue, you may also look at ConcurrentHashMap.
Java
class LinkedHashMap<K,V>
Java
class WeakHashMap<K,V>
Java
class Properties<K,V>
Java
class Provider<K,V>
Java
class EnumMap<K,V>
Java
class IdentityHashMap<K,V>
 
Java Collections based on interface SortedMap<E> (contains keys and values. Each key is associated with only one value, i.e. we get the value from the key. Keys are stored in a sorted form.)
Java
class TreeMap<K,V>
Java
class ConcurrentSkipListMap<K,V>
 
Java Collections based on interface ConcurrentMap<K, V> (contains keys and values. Each key is associated with only one value, i.e. we get the value from the key. Functions in ConcurrentMap are thread-safe and support fast multi-thread reads and writes.)
Java
class ConcurrentHashMap<K,V>
It is used when several threads can read and update data at the same time, while the card remains in the correct state. This is especially useful for storing intermediate or computed values that are frequently accessed by multiple threads.
ConcurrentHashMap   oracle.com ...
Java
class ConcurrentSkipListMap<K,V>
 
← Previous topic
Access modifiers (private, protected, public) for a class and for methods and fields. | Java
 
Next topic →
interface List<E> in Java
 
Your feedback ... Comments ...
   
Your Name
Your comment (www links can only be added by a logged-in user)

 
Download and install
• Installation JDK (download and install the Java library for Windows)
• Download and install IntelliJ IDEA to explore Java, Spring, Jakarta EE | Functionality and differences: Community | Ultimate
• Error "JDK is missing" | Java
Java (class, interface, collections, etc.)
• Create a simple console app in IntelliJ IDEA to learn Java
• Access modifiers (private, protected, public) for a class and for methods and fields. | Java
• Collections in Java
• interface List<E> in Java
• class ArrayList<E> in Java
• class Vector<E> in Java
• class Stack<E> in Java
• class CopyOnWriteArrayList<E> in Java
• interface Queue<E> in Java
• interface Deque<E> in Java
• class LinkedList<E> in Java
• interface Set in Java
• class HashSet<E> in Java
• class LinkedHashSet<E> in Java
• Collections.singletonList("Hello") returns an immutable list containing exactly one specified element | Java collection
• class Collections (all functions, algorithms) | Java
• stream.filter(...) select elements according to your criterion | Java collection | Example: allCars.stream().filter(item -> item.Price < 30000).toList()
• What is interface in Java ?
• Directly in the code (at runtime) we make an implementation for the interface | Java
• Threads in Java
• lambda is an unnamed method (no name and no class owned) | Java
• Exceptions and handling in Java. Example: try {...} catch (Exception e) {...}
• Why use throws Exception in the function name in Java? Answer: The method throws an exception and there is no handling of try catch. Example: float CalculateDensity(float mass, float volume) throws Exception { ... throw new Exception("Error! Volume is zero."); ... }
Java web application (servlet, jsp page, basic functionality and no frameworks)
• Creating a new simple web application (jsp web page) | Java, Maven
• Create a web servlet (the servlet is located on the web server, returns the result on request) | Java
• Installation Tomcat web server (download and install for Windows)
• Check, test Tomcat web server (create a new my.hml file)
• What is Maven
• What is a dynamic web page jsp (Java Server Page) ?
• How to install Smart Tomcat plugin in Intellij Idea
• Error "The SDK is not specified for module ... | Project SDK is not defined ..." in IntelliJ IDEA | Java
Spring in Java (Spring Framework, Spring Data, Spring Boot, ...)
• What is Spring? Why use Spring in Java?
• What is Spring Bean? What is Spring Container? IoC (inversion of control) | Creating a simple Spring project and configuration Spring Container in an XML file | Editor IntelliJ Idea and language Java
• What is Dependency Injection in Spring? Creating a simple Spring project with Dependency Injection in the constructor with the attributes @Component, @Autowired | Editor IntelliJ Idea and language Java
• Create a new Spring Web application (the request goes to the Controller → Controller creates a response as text or json) | Java, Spring Web, Spring Boot, Maven
• Creating a new Spring WebSocket application (Java WebSocket sends a message to the JavaScript WebSocket) | Java, Spring WebSocket, Spring Boot, Maven
• Create Azure Web App with the type Java (free). That is, create an empty web server
• Put the Java Spring web application in Azure
• Connect to the application Azure Web App (Java) via FTP | use File Explorer
• Error "The SDK is not specified for module ... | Project SDK is not defined ..." in IntelliJ IDEA | Java, Spring Boot
• How to install Spring WebSocket plugin in Intellij Idea
Jakarta EE / Java EE in Java (Web Applications, Web Services)
• What is Jakarta EE (Java EE)? | In which editor (program) is it convenient to write Jakarta EE (Java EE) code?
• Creating a simple web project in IntelliJ Idea Ultimate | Jakarta EE (Java EE)
Struts in Java (extends API Java Servlet using MVC)
• What is Struts | Java
Courses, training
• Course "Java developer" from Yandex
Interview
• Interviews on Java

  Ваши вопросы присылайте по почте: info@dir.by