- Java - Home
- Java - Overview
- Java - History
- Java - Features
- Java Vs. C++
- JVM - Java Virtual Machine
- Java - JDK vs JRE vs JVM
- Java - Environment Setup
- Java - Hello World Program
- Java - Comments
- Java - Basic Syntax
- Java - Variables
- Java - Data Types
- Java - Type Casting
- Java - Unicode System
- Java - User Input
- Java - Date & Time
Java Operators
- Java - Operators
- Java - Arithmetic Operators
- Java - Assignment Operators
- Java - Relational Operators
- Java - Logical Operators
- Java - Bitwise Operators
- Java Operator Precedence & Associativity
- Java - Unary Operators
Java Control Statements
- Java - Decision Making
- Java - If Else Statement
- Java - Switch Statement
- Java - Loop Control
- Java - For Loop
- Java - For-Each Loop
- Java - While Loop
- Java - Do While Loop
- Java - Break Statement
- Java - Continue Statement
Object Oriented Programming
- Java - OOPs Concepts
- Java - Object & Classes
- Java - Class Attributes
- Java - Class Methods
- Java - Methods
- Java - Variables Scope
- Java - Constructors
- Java - Access Modifiers
- Java - Inheritance
- Java - Aggregation
- Java - Polymorphism
- Java - Overriding
- Java - Method Overloading
- Java - Dynamic Binding
- Java - Static Binding
- Java - Instance Initializer Block
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java - Inner Classes
- Java - Static Class
- Java - Anonymous Class
- Java - Singleton Class
- Java - Wrapper Classes
- Java - Enums
- Java - Enum Constructor
- Java - Enum Strings
Java Built-in Classes
- Java - Number
- Java - Boolean
- Java - Characters
- Java - Arrays
- Java - Multi-Dimensional Arrays
- Java - Final Arrays
- Java - Math Class
Java File Handling
- Java - Files
- Java - Create a File
- Java - Write to File
- Java - Read Files
- Java - Delete Files
- Java - Directories
- Java - I/O Streams
Java Error & Exceptions
- Java - Exceptions
- Java - try-catch Block
- Java - try-with-resources
- Java - Multi-catch Block
- Java - Nested try Block
- Java - Finally Block
- Java - throw Exception
- Java - Exception Propagation
- Java - Built-in Exceptions
- Java - Custom Exception
- Java - Chained Exception
Java Multithreading
- Java - Multithreading
- Java - Thread Life Cycle
- Java - Creating a Thread
- Java - Starting a Thread
- Java - Joining Threads
- Java - Naming Thread
- Java - Thread Scheduler
- Java - Thread Pools
- Java - Main Thread
- Java - Thread Priority
- Java - Daemon Threads
- Java - Thread Group
- Java - Shutdown Hook
Java Synchronization
- Java - Synchronization
- Java - Block Synchronization
- Java - Static Synchronization
- Java - Inter-thread Communication
- Java - Thread Deadlock
- Java - Interrupting a Thread
- Java - Thread Control
- Java - Reentrant Monitor
Java Networking
- Java - Networking
- Java - Socket Programming
- Java - URL Processing
- Java - URL Class
- Java - URLConnection Class
- Java - HttpURLConnection Class
- Java - Socket Class
- Java - Generics
Java Collections
Java Interfaces
- Java - List Interface
- Java - Queue Interface
- Java - Map Interface
- Java - SortedMap Interface
- Java - Set Interface
- Java - SortedSet Interface
Java Data Structures
Java Collections Algorithms
Advanced Java
- Java - Command-Line Arguments
- Java - Lambda Expressions
- Java - Sending Email
- Java - Applet Basics
- Java - Javadoc Comments
- Java - Autoboxing and Unboxing
- Java - File Mismatch Method
- Java - REPL (JShell)
- Java - Multi-Release Jar Files
- Java - Private Interface Methods
- Java - Inner Class Diamond Operator
- Java - Multiresolution Image API
- Java - Collection Factory Methods
- Java - Module System
- Java - Nashorn JavaScript
- Java - Optional Class
- Java - Method References
- Java - Functional Interfaces
- Java - Default Methods
- Java - Base64 Encode Decode
- Java - Switch Expressions
- Java - Teeing Collectors
- Java - Microbenchmark
- Java - Text Blocks
- Java - Dynamic CDS archive
- Java - Z Garbage Collector (ZGC)
- Java - Null Pointer Exception
- Java - Packaging Tools
- Java - Sealed Classes
- Java - Record Classes
- Java - Hidden Classes
- Java - Pattern Matching
- Java - Compact Number Formatting
- Java - Garbage Collection
- Java - JIT Compiler
Java Miscellaneous
- Java - Recursion
- Java - Regular Expressions
- Java - Serialization
- Java - Strings
- Java - Process API Improvements
- Java - Stream API Improvements
- Java - Enhanced @Deprecated Annotation
- Java - CompletableFuture API Improvements
- Java - Marker Interface
- Java - Streams
- Java - Datetime Api
- Java 8 - New Features
- Java 9 - New Features
- Java 10 - New Features
- Java 11 - New Features
- Java 12 - New Features
- Java 13 - New Features
- Java 14 - New Features
- Java 15 - New Features
- Java 16 - New Features
Java APIs & Frameworks
Java Class References
- Java - Scanner
- Java - Arrays
- Java - Strings
- Java - Date
- Java - ArrayList
- Java - Vector
- Java - Stack
- Java - PriorityQueue
- Java - LinkedList
- Java - ArrayDeque
- Java - HashMap
- Java - LinkedHashMap
- Java - WeakHashMap
- Java - EnumMap
- Java - TreeMap
- Java - IdentityHashMap
- Java - HashSet
- Java - EnumSet
- Java - LinkedHashSet
- Java - TreeSet
- Java - BitSet
- Java - Dictionary
- Java - Hashtable
- Java - Properties
- Java - Collection
- Java - Array
Java Useful Resources
Java - Util Collections Class
Introduction
The Java Collections class consists exclusively of static methods that operate on or return collections.Following are the important points about Collections −
It contains polymorphic algorithms that operate on collections, "wrappers", which return a new collection backed by a specified collection.
The methods of this class all throw a NullPointerException if the collections or class objects provided to them are null.
Class declaration
Following is the declaration for java.util.Collections class −
public class Collections extends Object
Field
Following are the fields for java.util.Collections class −
static List EMPTY_LIST − This is the empty list (immutable).
static Map EMPTY_MAP − This is the empty map (immutable).
static Set EMPTY_SET − This is the empty set (immutable).
Class methods
| Sr.No. | Method & Description |
|---|---|
| 1 |
static <T> boolean addAll(Collection<? super T> c, T... elements)
This method adds all of the specified elements to the specified collection. |
| 2 |
static <T> Queue<T> asLifoQueue(Deque<T> deque)
This method returns a view of a Deque as a Last-in-first-out (Lifo) Queue. |
| 3 |
static <T> int binarySearch(List<? extends Comparable<? super T>> list, T key)
This method searches the specified list for the specified object using the binary search algorithm. |
| 4 |
static <E> Collection<E> checkedCollection(Collection<E> c, Class<E> type)
This method returns a dynamically typesafe view of the specified collection. |
| 5 |
static <E> List<E> checkedList(List<E> list, Class<E> type)
This method returns a dynamically typesafe view of the specified list. |
| 6 |
static <K,V> Map<K,V> checkedMap(Map<K,V> m, Class<K> keyType, Class<V> valueType)
This method returns a dynamically typesafe view of the specified map. |
| 7 |
static <K,V> Navigable<K,V> checkedNavigableMap(Navigable<K,V> m, Class<K> keyType, Class<V> valueType)
This method returns a dynamically typesafe view of the specified navigable map. |
| 8 |
static <E> NavigableSet<E> checkedNavigableSet(NavigableSet<E> s, Class<E> type)
This method returns a dynamically typesafe view of the specified navigable set. |
| 9 |
static <E> Queue<E> checkedQueue(Queue<E> s, Class<E> type)
This method returns a dynamically typesafe view of the specified queue. |
| 10 |
static <E> Set<E> checkedSet(Set<E> s, Class<E> type)
This method returns a dynamically typesafe view of the specified set. |
| 11 |
static <K,V> SortedMap<K,V> checkedSortedMap(SortedMap<K,V> m, Class<K> keyType, Class<V> valueType)
This method returns a dynamically typesafe view of the specified sorted map. |
| 12 |
static <E> SortedSet<E>checkedSortedSet(SortedSet<E> s, Class<E> type)
This method returns a dynamically typesafe view of the specified sorted set. |
| 13 |
static <T> void copy(List<? super T> dest, List<? extends T> src)
This method copies all of the elements from one list into another. |
| 14 |
static boolean disjoint(Collection<?> c1, Collection<?> c2)
This method returns true if the two specified collections have no elements in common. |
| 15 |
static <T> Enumeration <T> emptyEnumeration()
This method returns the empty enumeration. |
| 16 |
static <T> Iterator <T> emptyIterator()
This method returns the empty iterator. |
| 17 |
static <T> List<T> emptyList()
This method returns the empty list (immutable). |
| 18 |
static <T> ListIterator <T> emptyListIterator()
This method returns the empty list iterator. |
| 19 |
static <K,V> Map<K,V> emptyMap()
This method returns the empty map (immutable). |
| 20 |
static <K,V> NavigableMap<K,V> emptyNavigableMap()
This method returns the empty navigable map (immutable). |
| 21 |
static <T> NavigableSet<T> emptyNavigableSet()
This method returns the empty navigable set (immutable). |
| 22 |
static <T> Set<T> emptySet()
This method returns the empty set (immutable). |
| 23 |
static <K,V> SortedMap<K,V> emptySortedMap()
This method returns the empty sorted map (immutable). |
| 24 |
static <T> SortedSet<T> emptySortedSet()
This method returns the empty sorted set (immutable). |
| 25 |
static <T> Enumeration<T> enumeration(Collection<T> c)
This method returns an enumeration over the specified collection. |
| 26 |
static <T> void fill(List<? super T> list, T obj)
This method replaces all of the elements of the specified list with the specified element. |
| 27 |
static int frequency(Collection<?> c, Object o)
This method returns the number of elements in the specified collection equal to the specified object. |
| 28 |
static int indexOfSubList(List<?> source, List<?> target)
This method 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. |
| 29 |
static int lastIndexOfSubList(List<?> source, List<?> target)
This method 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. |
| 30 |
static <T> ArrayList<T> list(Enumeration<T> e)
This method returns an array list containing the elements returned by the specified enumeration in the order they are returned by the enumeration. |
| 31 |
static <T extends Object & Comparable<? super T> >T max(Collection<? extends T> coll)
This method returns the maximum element of the given collection, according to the natural ordering of its elements. |
| 32 |
static <T extends Object & Comparable<? super T>>T min(Collection<? extends T> coll)
This method Returns the minimum element of the given collection, according to the natural ordering of its elements. |
| 33 |
static <T> List<T> nCopies(int n, T o)
This method returns an immutable list consisting of n copies of the specified object. |
| 34 |
static <E> Set<E> newSetFromMap(Map<E,Boolean> map)
This method returns a set backed by the specified map. |
| 35 |
static <T> boolean replaceAll(List<T> list, T oldVal, T newVal)
This method replaces all occurrences of one specified value in a list with another. |
| 36 |
static void reverse(List<?> list)
This method reverses the order of the elements in the specified list. |
| 37 |
static <T> Comparator<T> reverseOrder()
This method returns a comparator that imposes the reverse of the natural ordering on a collection of objects that implement the Comparable interface. |
| 38 |
static void rotate(List<?> list, int distance)
This method rotates the elements in the specified list by the specified distance. |
| 39 |
static void shuffle(List<?> list)
This method randomly permutes the specified list using a default source of randomness. |
| 40 |
static <T> Set<T> singleton(T o)
This method returns an immutable set containing only the specified object. |
| 41 |
static <T> List<T> singletonList(T o)
This method returns an immutable list containing only the specified object. |
| 42 |
static <K,V> Map<K,V> singletonMap(K key, V value)
This method returns an immutable map, mapping only the specified key to the specified value. |
| 43 |
static <T extends Comparable<? super T>> void sort(List<T> list)
This method sorts the specified list into ascending order, according to the natural ordering of its elements. |
| 44 |
static void swap(List<?> list, int i, int j)
This method swaps the elements at the specified positions in the specified list. |
| 45 |
static <T> Collection<T> synchronizedCollection(Collection<T> c)
This method returns a synchronized (thread-safe) collection backed by the specified collection. |
| 46 |
static <T> List<T> synchronizedList(List<T> list)
This method returns a synchronized (thread-safe) list backed by the specified list. |
| 47 |
static <K,V> Map<K,V> synchronizedMap(Map<K,V> m)
This method returns a synchronized (thread-safe) map backed by the specified map. |
| 48 |
static <K,V> NavigableMap<K,V> synchronizedNavigableMap()
This method returns the synchronized navigable map (immutable). |
| 49 |
static <T> NavigableSet<T> synchronizedNavigableSet()
This method returns the synchronized navigable set (immutable). |
| 50 |
static <T> Set<T> synchronizedSet(Set<T> s)
This method returns a synchronized (thread-safe) set backed by the specified set. |
| 51 |
static <K,V> SortedMap<K,V> synchronizedSortedMap(SortedMap<K,V> m)
This method returns a synchronized (thread-safe) sorted map backed by the specified sorted map. |
| 52 |
static <T> SortedSet<T> synchronizedSortedSet(SortedSet<T> s)
This method returns a synchronized (thread-safe) sorted set backed by the specified sorted set. |
| 53 |
static <T> Collection<T> unmodifiableCollection(Collection<? extends T> c)
This method returns an unmodifiable view of the specified collection. |
| 54 |
static <T> List<T> unmodifiableList(List<? extends T> list)
This method returns an unmodifiable view of the specified list. |
| 55 |
static <K,V> Map<K,V> unmodifiableMap(Map<? extends K,? extends V> m)
This method returns an unmodifiable view of the specified map. |
| 56 |
static <K,V> NavigableMap<K,V> unmodifiedNavigableMap()
This method returns the unmodifiable navigable map (immutable). |
| 57 |
static <T> NavigableSet<T> unmodifiedNavigableSet()
This method returns the unmodifiable navigable set (immutable). |
| 58 |
static <T> Set<T> unmodifiableSet(Set<? extends T> s)
This method returns an unmodifiable view of the specified set. |
| 59 |
static <K,V> SortedMap<K,V> unmodifiableSortedMap(SortedMap<K,? extends V> m)
This method returns an unmodifiable view of the specified sorted map. |
| 60 |
static <T> SortedSet<T> unmodifiableSortedSet(SortedSet<T> s)
This method returns an unmodifiable view of the specified sorted set. |
Methods inherited
This class inherits methods from the following classes −
- java.util.Object