Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of continue keyword in Java stream?

  for (final Prices ppr : prices) {
    if (!currency.getCode().equals(ppr.getCurrency().getCode())) {
      continue;
    }
    return ppr.getPrice();
  }

Can the code above be converted into Java stream code? I am getting an error with the continue keyword...

like image 348
Saurabh Kumar Avatar asked Aug 03 '26 10:08

Saurabh Kumar


1 Answers

return prices.stream()
     .filter(ppr -> currency.getCode().equals(ppr.getCurrent().getCode()))
     .findFirst()
     .orElseThrow(NoSuchElementException::new);
like image 174
John Kugelman Avatar answered Aug 06 '26 00:08

John Kugelman