Creating an immutable collection

Dear all,I was wondering if there is a way to create an immutable collection in Java. In other words, what is the typical situation for which an optional operation (e.g., Collection.removeAll()) may throw an exception?Any help appreciated,Alexandre
[276 byte] By [godfroy_berna] at [2007-11-27 9:14:48]
# 1

You have the following method from the Collection

public static Collection unmodifiableCollection(Collection c)

Check

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collections.html#unmodifiableCollection(java.util.Collection)

for details

manuel.leiriaa at 2007-7-12 22:03:17 > top of Java-index,Java Essentials,Java Programming...
# 2
Look at the class java.util.Collections. It has several methods for doing this sort of thing, such as unmodifiableCollection
georgemca at 2007-7-12 22:03:17 > top of Java-index,Java Essentials,Java Programming...
# 3

> You have the following method from the Collection

>

> > public static Collection

> unmodifiableCollection(Collection c)

>

>

> Check

>

> http://java.sun.com/j2se/1.4.2/docs/api/java/util/Coll

> ections.html#unmodifiableCollection(java.util.Collecti

> on)

>

> for details

Collection is an interface, you meant Collections :-) I win Teh Duke!!

georgemca at 2007-7-12 22:03:17 > top of Java-index,Java Essentials,Java Programming...
# 4
Thanks!Alexandre
godfroy_berna at 2007-7-12 22:03:17 > top of Java-index,Java Essentials,Java Programming...
# 5
> Thanks!> > AlexandreYou're welcome.George: give me back my Duke! ;)
manuel.leiriaa at 2007-7-12 22:03:17 > top of Java-index,Java Essentials,Java Programming...
# 6
> > Thanks!> > > > Alexandre> > You're welcome.> > George: give me back my Duke! ;)I didn't get it :-( seems accuracy is not important any more, only punctuality :-(<off to sulk for a bit>
georgemca at 2007-7-12 22:03:17 > top of Java-index,Java Essentials,Java Programming...
# 7
> Collection is an interface, you meant Collections :-)> I win Teh Duke!!It's not Teh Duke, it's The DukeIt seems accuracy is not important any more, only punctuality :-(<out for a dump>best regards,Manuel Leiria
manuel.leiriaa at 2007-7-12 22:03:17 > top of Java-index,Java Essentials,Java Programming...