Java – Find Element in Array using Condition and Lambda

You can do it like this,

Optional<Preset> optional = Arrays.stream(presets)
                                   .filter(x -> "MyString".equals(x.getName()))
                                   .findFirst();

if(optional.isPresent()) {//Check whether optional has element you are looking for
    Preset p = optional.get();//get it from optional
}

You can read more about Optional here.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)