Java Collections addAll() Method21 Mar 2025 | 2 min read The addAll() is a method of Java Collections class which adds all of the specified elements to the specified collection. The elements to be added may be specified individually or as an array. SyntaxFollowing is the declaration of addAll() method: Parameter
ReturnsThe addAll() method returns true if the collection changed as a result of the method call. ExceptionsUnsupportedOperationException- If collection c does not support the add operation. NullPointerException- If elements contain null values and c does not permit null elements, or if c or elements are null. IllegalArgumentException- If some properties of a value in elements prevent it from being added to c. Compatibility VersionJava 1.5 and above Example 1Output: Boolean Result: true Collection Value: [1, 2, 3, 4, 5] Example 2Output: The List are: [Rahul, Karthik, OM, Shiva, Anand, Prem] Boolean Result: true Collection Value: [Rahul, Karthik, OM, Shiva, Anand, Prem, Rahul, OM, Prem] Example 3Output: Initial collection value: [TpointTech, SSSIT.COM, Hindi100.COM] Boolean Result: true Final collection value: [TpointTech, SSSIT.COM, Hindi100.COM, Rank1, Rank2, Rank3] Next TopicJava Collections Class |
Java Collections Method The method of Java Collections class is used to replace all occurrences of one specified value in a list with the other specified value. Syntax Following is the declaration of method: public static <T> boolean replaceAll(List<T> list, T oldVal, T newVal) Parameter Parameter Description Required/Optional list It...
2 min read
Java Collections Method The method of Java Collections class is used to get an unmodifiable view of the specified list. If any attempt occurs to modify the returned list whether direct or via its iterator, results in an UnsupportedOperationException. Syntax Following is the declaration of ...
2 min read
The sort() method of Java Collections class is used to sort the elements presents in the specified list. There is two different types of Java sort() method which can be differentiated depending on its parameter. These are: Java Collections sort(list) Method Java Collections sort(list, comp) Method Java Collections...
3 min read
Java Collections Method The method of Java Collections class returns an empty sorted map which is immutable. Syntax Following is the declaration of method: public static final <K,V> SortedMap<K,V> Parameter This method does not accept any parameter. Returns The method returns an empty immutable Sorted Map. Exceptions NA Compatibility Version Java 1.8...
1 min read
Java Collections Method The method of Java Collections class returns an empty map which is immutable. Syntax Following is the declaration of method: public static final <K,V> Map<K,V> Parameter This method does not accept any parameter. Returns The method returns an empty immutable Map. Exceptions NA Compatibility Version Java 1.5 and...
1 min read
Java Collections Method The method of Java Collections class is used to get a synchronized (thread-safe) navigable map backed by the specified navigable map. Syntax Following is the declaration of method: public static <K,V> NavigableMap<K,V> synchronizedNavigableMap(NavigableMap<K,V> m) Parameter Parameter Description Required/Optional m It is the navigable map which will be wrapped in...
2 min read
Java Collections Method The method of Java Collections class is used to get a synchronized (thread-safe) collection backed by the specified list. Syntax Following is the declaration of method: public static <T> List<T> synchronizedList(List<T> list) Parameter Parameter Description Required/Optional list It is the list which will be wrapped in a synchronized list. Required Returns The...
2 min read
Java Collections Method The method of Java Collections class is used to get an Iterator that has no elements. Syntax Following is the declaration of method: Parameter This method does not accept any parameter. Returns The method returns an empty Iterator. Exceptions NA Compatibility Version Java 1.7 and above Example 1 import java.util.*; public class...
2 min read
Java Collections Method The method of Java Collections class is used to get the starting position of the first occurrence of the specified target list within the specified source list. It returns -1 if there is no such occurrence in the specified list. Syntax Following is...
3 min read
Java Collections Method The method of Java Collections class is used to get an enumeration that has no elements. Syntax Following is the declaration of method: public static <T> Enumeration<T> Parameter This method does not accept any parameter. Returns The method returns an empty enumeration. Exceptions NA Compatibility Version Java 1.7...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India