Returns an immutable collection containing only the specified object. The returned set is serializable.
/**
 * Set<T> java.util.Collections.singleton(T var0)
 * https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#singleton-T-
 */
Set<String> aa = Collections.singleton("AA");


/**
 * List<T> java.util.Collections.singletonList(T var0)
 * https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#singletonList-T-
 */
List<String> bb = Collections.singletonList("BB");


/**
 * Map<K, V> java.util.Collections.singletonMap(K var0, V var1)
 * https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#singletonMap-K-V-
 */
Map<String, String> cc = Collections.singletonMap("CCKey", "CCVal");

 

 

refer:

https://stackoverflow.com/questions/4801794/use-of-javas-collections-singletonlist
https://stackoverflow.com/questions/31599467/what-is-the-benefit-for-collections-singleton-to-return-a-set-instead-of-a-col
 

    咪卡恰比 發表在 痞客邦 留言(0) 人氣()