StringUtils.java
package practice;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
 * Utils
 * 
 * @author me
 *
 */
public class Practice {
	/** String list */
	private static final List<String> INTEGER_LIST = Arrays.asList(null, "", " ", "0", "1", "2");
	/**
	 * main
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			run(INTEGER_LIST);
		} catch (NumberFormatException e) {
			echo.accept("・ Ω ・ v");
		}
	}
	/**
	 * run
	 * 
	 * @param list <E> The element type of this list.
	 * @throws NumberFormatException if conversion to numeric number is impossible.
	 */
	private static void run(List<String> list) throws NumberFormatException {
		echo.accept(list.stream().filter(notBlank).map(Integer::parseInt)
				.collect(Collectors.summingInt(Integer::intValue)));
	}
	/** not null */
	static Predicate<String> notNull = v -> Optional.ofNullable(v).isPresent();
	/** not space */
	static Predicate<String> notSpace = v -> !v.equals(" ");
	/** StringUtils.isBlank */
	static Predicate<String> notBlank = v -> notNull.test(v) && !v.isEmpty()
			&& Arrays.asList(v.split("")).stream().anyMatch(notSpace);
	/** out */
	static Consumer<Object> echo = v -> System.out.println(v);
}
3
Même si vous pouvez créer le vôtre, il est plus rapide d'ajouter la bibliothèque. Mais s'il se termine par quelques lignes, vous n'avez pas à l'utiliser une par une. J'ai l'impression de pouvoir tout résoudre car java existe déjà Je n'ai pas vu du tout apache.common.lang récemment ...
Recommended Posts