On Apr 30, 2:47 pm, "sak...@gmail.com" <sak...@gmail.com> wrote:
> is there a way to return a copy of collection instead of referance to
> collection itself
[quoted text clipped - 11 lines]
>
> thanks
There are a few options.
Collections.unmodifiable* will give you a wrapper Map or Collection
which the client cannot modify. It will be a view of the existing
collection, so that if your code changes the Map, the unmodifiable map
will change, but any calls to set/put in the unmodifiable map will
through unsupported exception.
Alternatively, you can usually
public Map<T> getMap() {
return new HashMap<T>(oldMap);
}
Hope this helps.