lambdaj has a selectUnique method that throws an exception if there is more than one element satisfying the condition expressed by the given match. Since you do not have any specific condition for matching, you need a Matcher that always returns true (it does not seem to me that hamcrest provides such a Matcher out of the box, but it is trivial to implement it), or maybe you want to check that the object (only ) in the list is at least non-zero, so you can achieve this result with:
selectUnique(list, Matchers.notNullValue());
source share