Java Collections fill() MethodThe 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. SyntaxFollowing is the declaration of fill() method: Parameter
ReturnsThe fill() method does not return anything. ExceptionsUnsupportedOperationException- This exception will be thrown if the specified list or its list-iterator does not support the set operation. Compatibility VersionJava 1.4 and above Example 1Test it NowOutput: List elements before Replacements: [AAA, BBB, CCC] List elements after Replacements: [JavaTpoint, JavaTpoint, JavaTpoint] Example 2Test it NowOutput: 551 551 551 551 Example 3Test it NowOutput: Before Fill: [Hi, Hi, Hi, Hi, Hi, Hi] After Fill: [Hello, Hello, Hello, Hello, Hello, Hello] Next TopicJava Collections Class |
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