Javatpoint Logo
Javatpoint Logo

Java Collections fill() Method

The fill() method of Java Collections class is used to replace all of the elements of the specified list with the specified elements. This method filled all the elements with the same values.


Following is the declaration of fill() method:


Parameter Description Required/Optional
list It is the list to be filled with the specified elements. Required
obj It is the element to fill the specified list. Required


The fill() method does not return anything.


UnsupportedOperationException- This exception will be thrown if the specified list or its list-iterator does not support the set operation.

Compatibility Version

Java 1.4 and above

Example 1

Test it Now


List elements before Replacements: [AAA, BBB, CCC]
List elements after Replacements: [JavaTpoint, JavaTpoint, JavaTpoint]

Example 2

Test it Now


551 551 551 551 

Example 3

Test it Now


Before Fill: [Hi, Hi, Hi, Hi, Hi, Hi]
After Fill: [Hello, Hello, Hello, Hello, Hello, Hello]

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA