Java Collections nCopies() MethodThe nCopies() method of Java Collections class is used to get an immutable list consisting of n copies of the specified object. SyntaxFollowing is the declaration of nCopies() method: Parameter
ReturnsThe nCopies() method returns an immutable list consisting of n copies of the specified object. ExceptionsIllegalArgumentException- It throws this exception if the number of elements is less then zero i.e. n < 0. Compatibility VersionJava 1.4 and above Example 1Test it NowOutput: Output: [JavaTpoint, JavaTpoint, JavaTpoint] Example 2Test it NowOutput: Output of Atomic Integer are: [0, 0, 0] [1, 1, 1] Example 3Test it NowOutput: List elements: SSSIT.COM SSSIT.COM SSSIT.COM SSSIT.COM SSSIT.COM 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