Java Collection Unique uniqueResult(Collection results)

Here you can find the source of uniqueResult(Collection results)

Description

Method to take a get a unique result from a set and return it or null.

License

BSD License

Parameter

Parameter Description
T the type of the returned object
results the set of results returned from a query

Return

the first result in the set or null

Declaration

public static <T> T uniqueResult(Collection<T> results) 

Method Source Code

//package com.java2s;
// Distributed under the OSI-approved BSD 3-Clause License.

import java.util.Collection;

public class Main {
    /**/*from ww  w  .  j a  va2s  .c  o  m*/
     * Method to take a get a unique result from a set and return it or null.
     * 
     * @param <T> the type of the returned object
     * @param results the set of results returned from a query
     * @return the first result in the set or null
     */
    public static <T> T uniqueResult(Collection<T> results) {
        return results.isEmpty() ? null : results.iterator().next();
    }
}

Related

  1. hasUniqueObject(Collection collection)
  2. hasUniqueObject(Collection collection)
  3. unique(Collection c)
  4. unique(Collection c, Collection result)
  5. uniqueIdNotIn(String prefix, Collection exclusions)
  6. uniqueResult(final Collection c)