Share code snippets.

TrimListStringsJava8

Created 1 year ago by anonymous
trim a list of strings using Java 8 and filter the blank strings
import org.apache.commons.lang3.StringUtils;
....

 List<String> filteredAndTrimmed = Arrays.asList("abc ", " cd", "", "gh").stream().map(StringUtils::trim).filter(StringUtils::isNotBlank)
			.collect(Collectors.toList());
		 
filteredAndTrimmed.forEach(System.out::println);

//output is 
abc
cd
gh