Java Collections addAll() MethodThe addAll() is a method of Java Collections class which adds all of the specified elements to the specified collection. The elements to be added may be specified individually or as an array. SyntaxFollowing is the declaration of addAll() method: Parameter
ReturnsThe addAll() method returns true if the collection changed as a result of the method call. ExceptionsUnsupportedOperationException- If collection c does not support the add operation. NullPointerException- If elements contain null values and c does not permit null elements, or if c or elements are null. IllegalArgumentException- If some properties of a value in elements prevent it from being added to c. Compatibility VersionJava 1.5 and above Example 1Test it NowOutput: Boolean Result: true Collection Value: [1, 2, 3, 4, 5] Example 2Test it NowOutput: The List are: [Rahul, Karthik, OM, Shiva, Anand, Prem] Boolean Result: true Collection Value: [Rahul, Karthik, OM, Shiva, Anand, Prem, Rahul, OM, Prem] Example 3Test it NowOutput: Initial collection value: [JavaTpoint, SSSIT.COM, Hindi100.COM] Boolean Result: true Final collection value: [JavaTpoint, SSSIT.COM, Hindi100.COM, Rank1, Rank2, Rank3] 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