dir.by  
Поиск >>

Компьютер, программы
→
Java
→
Java (class, interface, collections, etc.)
 class Collections (all functions, algorithms) | Java 
посмотрели 976 раз
обновлено: 25 September 2026
  Java  
public class Collections extends Object
{
     static final List EMPTY_LIST; // The empty list (immutable)
     static final Map EMPTY_MAP; // The empty map (immutable).
     static final Set EMPTY_SET; // The empty set (immutable).

     // Adds all of the specified elements to the specified collection.
     static <T> boolean addAll(Collection<? super T> c, T... elements);

     // Returns a view of a Deque as a Last-in-first-out (Lifo) Queue.
     static <T> Queue<T> asLifoQueue(Deque<T> deque);

     // Searches the specified list for the specified object using the binary search algorithm.
     static <T> int binarySearch(List<? extends Comparable<? super T>> list, T key);

     // Searches the specified list for the specified object using the binary search algorithm.
     static <T> int binarySearch(List<? extends T> list, T key, Comparator<? super T> c);

     // Returns a dynamically typesafe view of the specified collection.
     static <E> Collection<E> checkedCollection(Collection<E> c, Class<E> type);

     // Returns a dynamically typesafe view of the specified list.
     static <E> List<E> checkedList(List<E> list, Class<E> type);

     // Returns a dynamically typesafe view of the specified map.
     static <K,V> Map<K,V> checkedMap(Map<K,V> m, Class<K> keyType, Class<V> valueType);

     // Returns a dynamically typesafe view of the specified navigable map.
     static <K,V> NavigableMap<K,V> checkedNavigableMap(NavigableMap<K,V> m, Class<K> keyType, Class<V> valueType);

     // Returns a dynamically typesafe view of the specified navigable set.
     static <E> NavigableSet<E> checkedNavigableSet(NavigableSet<E> s, Class<E> type)

     // Returns a dynamically typesafe view of the specified queue.
     static <E> Queue<E> checkedQueue(Queue<E> queue, Class<E> type);

     // Returns a dynamically typesafe view of the specified set.
     static <E> Set<E> checkedSet(Set<E> s, Class<E> type);

     // Returns a dynamically typesafe view of the specified sorted map.
     static <K,V> SortedMap<K,V> checkedSortedMap(SortedMap<K,V> m, Class<K> keyType, Class<V> valueType);

     // Returns a dynamically typesafe view of the specified sorted set.
     static <E> SortedSet<E> checkedSortedSet(SortedSet<E> s, Class<E> type);

     // Copies all of the elements from one list into another.
     static <T> void copy(List<? super T> dest, List<? extends T> src);

     // Returns true if the two specified collections have no elements in common.
     static boolean disjoint(Collection<?> c1, Collection<?> c2);

     // Returns an enumeration that has no elements.
     static <T> Enumeration<T> emptyEnumeration();

     // Returns an iterator that has no elements.
     static <T> Iterator<T> emptyIterator();

     // Returns an empty list (immutable).
     static final <T> List<T> emptyList();

     // Returns a list iterator that has no elements.
     static <T> ListIterator<T> emptyListIterator();

     // Returns an empty map (immutable).
     static final <K,V> Map<K,V> emptyMap();

     // Returns an empty navigable map (immutable).
     static final <K,V> NavigableMap<K,V> emptyNavigableMap();

     // Returns an empty navigable set (immutable).
     static <E> NavigableSet<E> emptyNavigableSet();

     // Returns an empty set (immutable).
     static final <T> Set<T> emptySet();

     // Returns an empty sorted map (immutable).
     static final <K,V> SortedMap<K,V> emptySortedMap();

     // Returns an empty sorted set (immutable).
     static <E> SortedSet<E> emptySortedSet();

     // Returns an enumeration over the specified collection.
     static <T> Enumeration<T> enumeration(Collection<T> c);

     // Replaces all of the elements of the specified list with the specified element.
     static <T> void fill(List<? super T> list, T obj);

     // Returns the number of elements in the specified collection equal to the specified object.
     static int frequency(Collection<?> c, Object o);

     // Returns the starting position of the first occurrence of the specified target list within the specified source list, or -1 if there is no such occurrence.
     static int indexOfSubList(List<?> source, List<?> target);

     // Returns the starting position of the last occurrence of the specified target list within the specified source list, or -1 if there is no such occurrence.
     static int lastIndexOfSubList(List<?> source, List<?> target)

     // Returns an array list containing the elements returned by the specified enumeration in the order they are returned by the enumeration.
     static <T> ArrayList<T> list(Enumeration<T> e);

     // Returns the maximum element of the given collection, according to the natural ordering of its elements.
     static <T extends Object & Comparable<? super T>> max(Collection<? extends T> coll);

     // Returns the maximum element of the given collection, according to the order induced by the specified comparator.
     static <T> T max(Collection<? extends T> coll, Comparator<? super T> comp);

     // Returns the minimum element of the given collection, according to the natural ordering of its elements.
     static <T extends Object & Comparable<? super T>> T min(Collection<? extends T> coll);

     // Returns the minimum element of the given collection, according to the order induced by the specified comparator.
     static <T> T min(Collection<? extends T> coll, Comparator<? super T> comp);

     // Returns an immutable list consisting of n copies of the specified object.
     static <T> List<T> nCopies(int n, T o);

     // Returns a sequenced set backed by the specified map.
     static <E> SequencedSet<E> newSequencedSetFromMap(SequencedMap<E,Boolean> map);

     // Returns a set backed by the specified map.
     static <E> Set<E> newSetFromMap(Map<E,Boolean> map);

     // Replaces all occurrences of one specified value in a list with another.
     static <T> boolean replaceAll(List<T> list, T oldVal, T newVal);

     // Reverses the order of the elements in the specified list.
     static void reverse(List<?> list);

     // Returns a comparator that imposes the reverse of the natural ordering on a collection of objects that implement the Comparable interface.
     static <T> Comparator<T> reverseOrder();

     // Returns a comparator that imposes the reverse ordering of the specified comparator.
     static <T> Comparator<T> reverseOrder(Comparator<T> cmp);

     // Rotates the elements in the specified list by the specified distance.
     static void rotate(List<?> list, int distance);

     // Randomly permutes the specified list using a default source of randomness.
     static void shuffle(List<?> list);

     // Randomly permute the specified list using the specified source of randomness.
     static void shuffle(List<?> list, Random rnd);

     // Randomly permute the specified list using the specified source of randomness.
     static void shuffle(List<?> list, RandomGenerator rnd);

     // Returns an immutable set containing only the specified object.
     static <T> Set<T> singleton(T o);

     // Returns an immutable list containing only the specified object.
     static <T> List<T> singletonList(T o);

     // Returns an immutable map, mapping only the specified key to the specified value.
     static <K,V> Map<K,V> singletonMap(K key, V value);

     // Sorts the specified list into ascending order, according to the natural ordering of its elements.
     static <T extends Comparable<? super T>> void sort(List<T> list);

     // Sorts the specified list according to the order induced by the specified comparator.
     static <T> void sort(List<T> list, Comparator<? super T> c);

     // Swaps the elements at the specified positions in the specified list.
     static void swap(List<?> list, int i, int j);

     // Returns a synchronized (thread-safe) collection backed by the specified collection.
     static <T> Collection<T> synchronizedCollection(Collection<T> c);

     // Returns a synchronized (thread-safe) list backed by the specified list.
     static <T> List<T> synchronizedList(List<T> list);

     // Returns a synchronized (thread-safe) map backed by the specified map.
     static <K,V> Map<K,V> synchronizedMap(Map<K,V> m);

     // Returns a synchronized (thread-safe) navigable map backed by the specified navigable map.
     static <K,V> NavigableMap<K,V> synchronizedNavigableMap(NavigableMap<K,V> m);

     // Returns a synchronized (thread-safe) navigable set backed by the specified navigable set.
     static <T> NavigableSet<T> synchronizedNavigableSet(NavigableSet<T> s);

     // Returns a synchronized (thread-safe) set backed by the specified set.
     static <T> Set<T> synchronizedSet(Set<T> s);

     // Returns a synchronized (thread-safe) sorted map backed by the specified sorted map.
     static <K,V> SortedMap<K,V> synchronizedSortedMap(SortedMap<K,V> m);

     // Returns a synchronized (thread-safe) sorted set backed by the specified sorted set.
     static <T> SortedSet<T> synchronizedSortedSet(SortedSet<T> s);

     // Returns an unmodifiable view of the specified collection.
     static <T> Collection<T> unmodifiableCollection(Collection<? extends T> c);

     // Returns an unmodifiable view of the specified list.
     static <T> List<T> unmodifiableList(List<? extends T> list);

     // Returns an unmodifiable view of the specified map.
     static <K,V> Map<K,V> unmodifiableMap(Map<? extends K,? extends V> m);

     // Returns an unmodifiable view of the specified navigable map.
     static <K,V> NavigableMap<K,V> unmodifiableNavigableMap(NavigableMap<K,? extends V> m);

     // Returns an unmodifiable view of the specified navigable set.
     static <T> NavigableSet<T> unmodifiableNavigableSet(NavigableSet<T> s);

     // Returns an unmodifiable view of the specified SequencedCollection.
     static <T> SequencedCollection<T> unmodifiableSequencedCollection(SequencedCollection<? extends T> c);

     // Returns an unmodifiable view of the specified SequencedMap.
     static <K,V> SequencedMap<K,V> unmodifiableSequencedMap(SequencedMap<? extends K,? extends V> m);

     // Returns an unmodifiable view of the specified SequencedSet.
     static <T> SequencedSet<T> unmodifiableSequencedSet(SequencedSet<? extends T> s);

     // Returns an unmodifiable view of the specified set.
     static <T> Set<T> unmodifiableSet(Set<? extends T> s);

     // Returns an unmodifiable view of the specified sorted map.
     static <K,V> SortedMap<K,V> unmodifiableSortedMap(SortedMap<K,? extends V> m);

     // Returns an unmodifiable view of the specified sorted set.
     static <T> SortedSet<T> unmodifiableSortedSet(SortedSet<T> s);
}


     Learn more about methods in the Java documentation:https://docs.oracle.com ...
 
← Previous topic
Collections.singletonList("Hello") returns an immutable list containing exactly one specified element | Java collection
 
Next topic →
stream.filter(...) select elements according to your criterion | Java collection | Example: allCars.stream().filter(item -> item.Price < 30000).toList()
 
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