-
Notifications
You must be signed in to change notification settings - Fork 547
Open
Description
Existe alguma inconsistência ou má prática em fazer dessa forma?
Além disso, existe alguma maneira mais eficiente de fazer a busca do elemento?
public class Desafio7 {
public static void main(String[] args) {
List<Integer> numeros = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5, 4, 3);
int maiorNumero = numeros.stream()
.max(Comparator.naturalOrder())
.orElseThrow(() -> new NoSuchElementException("Nao foi possivel achar o elemento"));
int segundoMaiorNumero = numeros.stream()
.filter(n -> n != maiorNumero)
.max(Comparator.naturalOrder())
.orElseThrow(() -> new NoSuchElementException("Nao foi possivel achar o elemento"));
System.out.println(segundoMaiorNumero);
}
}Metadata
Metadata
Assignees
Labels
No labels