Java Stream check String array with all distinct values

Description

Java Stream check String array with all distinct values


//package com.demo2s;

import java.util.stream.Stream;

public class Main {
    public static void main(String[] argv) throws Exception {
        String[] strings = new String[] { "CSS", "HTML", "Java", null, 
        "demo2s.com", "Javascript 123" };
        System.out.println(allDistinct(strings));
    }//from   w w  w .j a  v a2s  .c om

    private static boolean allDistinct(String[] strings) {
        return Stream.of(strings).distinct().count() == strings.length;
    }
}



PreviousNext

Related