Assert List is Unique Element - Java java.lang

Java examples for java.lang:Assert

Description

Assert List is Unique Element

Demo Code


//package com.java2s;

import java.util.List;

public class Main {
    public static void main(String[] argv) throws Exception {
        List list = java.util.Arrays.asList("asdf", "java2s.com");
        System.out.println(isUniqueElement(list));
    }//from w  w w  .  j  a v  a 2s .co m

    public static <E> boolean isUniqueElement(List<E> list) {
        return (isNotNull(list) && list.size() == 1);
    }

    public static <E> boolean isUniqueElement(E... array) {
        return (isNotNull(array) && array.length == 1);
    }

    public static boolean isNotNull(Object object) {
        return object != null;
    }
}

Related Tutorials