Java List Single Value single(List list)

Here you can find the source of single(List list)

Description

single

License

Open Source License

Declaration

public static <T> T single(List<T> list) 

Method Source Code

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

import java.util.List;

public class Main {
    public static <T> T single(List<T> list) {
        if (list.size() == 1) {
            return list.get(0);
        } else if (list.size() == 0) {
            throw new RuntimeException("No results found!");
        } else {/*from   www.  j  a  v a 2 s.c  o m*/
            throw new RuntimeException("More results returned than one!");
        }
    }
}

Related

  1. singleElementList(T element)
  2. singleItemAsList(T item)
  3. singleQuoatanizeStringList(List entries)
  4. singletonList(final T source)