Showing posts with label Filter. Show all posts
Showing posts with label Filter. Show all posts

Monday, February 1, 2021

Streams, Lamdas, Method References- Examples

https://www.baeldung.com/java-stream-filter-lambda
https://www.baeldung.com/java-maps-streams
https://www.baeldung.com/java-method-references

List<String> isbnCodes = books.entrySet().stream()
  .filter(e -> e.getValue().startsWith("Effective Java"))
  .map(Map.Entry::getKey)
  .collect(Collectors.toList());



replaceSpecialCharUtil.convertResourceBundleToMap(junkCharResource).entrySet().stream()
				.forEach(entry -> logger.info(entry.getKey() + " : " + entry.getValue()));

junkCharResource.getKeys().asIterator().forEachRemaining(key -> logger.info(key));

Set<String> keySet = messageSourceProperties.keySet().stream()
				.map(Object::toString).collect(Collectors.toSet());



We can achieve this by leveraging a simple lambda expression calling the StringUtils.capitalize() method directly:

messages.forEach(word -> StringUtils.capitalize(word));

Or, we can use a method reference to simply refer to the capitalize static method:

messages.forEach(StringUtils::capitalize);

Notice that method references always utilize the :: operator.

Azure - Pipeline - Add Approver for Stage

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/approvals?view=azure-devops&tabs=check-pass