24.20. Chapter Summary

 
[Page 737 ( continued )]

22.10. Singleton and Unmodifiable Collections and Maps

The Collections class contains the static methods for lists and collections. It also contains the methods for creating singleton sets, lists, and maps, and for creating unmodifiable sets, lists, and maps, as shown in Figure 22.25.

Figure 22.25. The Collections class contains the static methods for creating singleton and unmodifiable sets, lists, and maps.
(This item is displayed on page 738 in the print version)

The Collections class defines three constants: one for an empty set, one for an empty list, and one for an empty map ( EMPTY_SET , EMPTY_LIST , and EMPTY_MAP ). The class also provides the singleton(Object o) method for creating an immutable set containing only a single item, the singletonList(Object o) method for creating an immutable list containing only a single item, and the singletonMap(Object key, Object value) method for creating an immutable map containing only a single mapping.


[Page 738]

The Collections class also provides six static methods for creating read-only collections: unmodifiableCollection(Collection c) , unmodifiableList(List list) , unmodifiableMap(Map m) , unmodifiableSet(Set set) , unmodifiableSortedMap(SortedMap m ), and unmodifiableSortedSet(SortedSet s) . The read-only collections prevent the data in the collections from being modified, and, as well, offer better performance for read-only operations.

 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net