The fill() method of java.util.Collections class is used to replace all of the elements of the specified list with the specified element.
This method runs in linear time.
public static void fill(List list, T obj)
Parameters: This method takes following argument as parameter
- list – the list to be filled with the specified element.
- obj – The element with which to fill the specified list.
Below are the examples to illustrate the fill() method
List elements before fill: [A, B, C] List elements after fill: [TAJMAHAL, TAJMAHAL, TAJMAHAL]
List elements before fill: [20, 30, 40] List elements after fill: [500, 500, 500]
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.