Skip to content

Instantly share code, notes, and snippets.

@gaalha
Last active March 4, 2020 14:18
Show Gist options
  • Save gaalha/6d35395b93d4b930cc72c8f69e16370a to your computer and use it in GitHub Desktop.
Save gaalha/6d35395b93d4b930cc72c8f69e16370a to your computer and use it in GitHub Desktop.
// Catch valores nulos
disabledUsersOnLDAP.stream()
.map(User::getUsername)
.map(usersRepository::findEnabledByUsername)
.filter(Objects::nonNull) // <-- Util
.forEach(userEntity -> userEntity.setEnabled(false));
// Obtener el número máximo de una lista
Integer lastPaysheetPaymentId = lst.stream()
.mapToInt(VwRecalculatedRent::getPaysheetPaymentDetailId)
.max()
.orElseThrow(NoSuchElementException::new);
// Sumar valores de una lista
Double promisesAmount = accountPaymentsList.stream()
.mapToDouble(AccountPayments::getAmount)
.filter(Objects::nonNull)
.sum();
// Guardar una propiedad de una lista en otra lista
List<Integer> lstCurrent = paymentPlanListOfCurrentMonth.stream()
.map(VwPaymentPlanToChart::getCount)
.collect(Collectors.toList());
// Unir dos listas sin repetir valores iguales
ArrayList<String> listOne = new ArrayList<>(Arrays.asList("a", "b", "c", "d", "e"));
ArrayList<String> listTwo = new ArrayList<>(Arrays.asList("a", "b", "c", "f", "g"));
List<String> combinedList = Stream.concat(
listOne.stream(),
listTwo.stream())
.distinct()
.collect(Collectors.toList());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment