Java Collection Convert toSingleton(Collection l)

Here you can find the source of toSingleton(Collection l)

Description

to Singleton

License

Open Source License

Declaration

public static <T> T toSingleton(Collection<T> l) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Collection;
import java.util.Iterator;

public class Main {
    public static <T> T toSingleton(Collection<T> l) {
        return toSingleton(l.iterator());
    }/*from  www  . j av  a2s . com*/

    public static <T> T toSingleton(Iterator<T> it) {
        if (!it.hasNext())
            return null;
        return it.next();
    }

    public static <T> T toSingleton(T[] l) {
        if (l.length == 0)
            return null;
        return l[0];
    }
}

Related

  1. toPrimitiveIntegerArray(Collection collection)
  2. toReadableString(Collection collection)
  3. toSeparatedString(Collection items, String separator)
  4. toSeperatedString(final Collection list)
  5. toSet(Collection c)
  6. toSQLIn(Collection values)
  7. toStringBuilder( Collection collection, String delimiter)
  8. toStringColl(Collection set)
  9. toSV(Collection collection, String separator)