Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

How can we pass a Collection as an argument to a method and ensure that method will not be able to modify it?

Pragya Keshap answered on February 4, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers


How can we pass a Collection as an argument to a method and ensure that method will not be able to modify it?

0

To ensure that a method is not able to modify a Collection passed as

an argument, we have to make the Collection read only.

We can make a read only collection by using

Collections.unmodifiableCollection(Collection c) method.

This will make sure that any operation to change the collection will

throw UnsupportedOperationException.

https://learning.oreilly.com/library/view/head-first-java/0596009208/ch04.html#how_do_objects_in_an_array_behavequestio

Popularity 1/10 Helpfulness 1/10 Language java
Source: Grepper
Tags: java
Link to this answer
Share Copy Link
Contributed on Feb 04 2023
Pragya Keshap
0 Answers  Avg Quality 2/10


X

Continue with Google

By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
X
Grepper Account Login Required

Oops, You will need to install Grepper and log-in to perform this action.