Skip to main content
IBM 
ShopSupportDownloads
IBM HomeProductsConsultingIndustriesNewsAbout IBM
IBM : developerWorks : Java : Education - online courses
Java Collections Framework
Download tutorial zip fileView letter-sized PDF fileView A4-sized PDF fileE-mail this tutorial to a friend
Main menuSection menuGive feedback on this tutorialPreviousNext
4. Special collection implementations
  


Singleton collections page 4 of 6


The Collections class provides for the ability to create single element sets fairly easily. Instead of having to create the Set and fill it in in separate steps, you can do it all at once. The resulting Set is immutable.

Set set = Collection.singleton("Hello");

The Java 2 SDK, Standard Edition, version 1.3 adds the ability to create singleton lists and maps, too:

  • List singletonList(Object element)
  • Map singletonMap(Object key, Object value)

Main menuSection menuGive feedback on this tutorialPreviousNext
PrivacyLegalContact