![]() |
VOOZH | about |
The Collections class in Java provides several utility methods to work with collection objects such as List, Set, and Map. One such useful method is Collections.fill(), which is used to replace all elements of a list with a specified value.
Example: Filling an Integer List
[100, 100, 100]
Explanation:
Note: Collections.fill() throws UnsupportedOperationException if the list is immutable or does not support the set() operation.
public static <T> void fill(List<? super T> list, T obj)
Parameter:
Example : Filling a String List
[Programming, Programming, Programming]
Explanation:
Example: Collections.fill() with Custom Objects
[Default, Default]
Explanation: