Java tutorial
//package com.java2s; // From org.springframework.util.StringUtils, under Apache License 2.0 public class Main { /** * Check whether the given CharSequence contains any whitespace characters. * * @param seq the CharSequence to check (may be {@code null}) * @return {@code true} if the CharSequence is not empty and * contains at least 1 whitespace character * @see java.lang.Character#isWhitespace * @since 3.0 */ // From org.springframework.util.StringUtils, under Apache License 2.0 public static boolean containsWhitespace(final CharSequence seq) { if (isEmpty(seq)) { return false; } final int strLen = seq.length(); for (int i = 0; i < strLen; i++) { if (Character.isWhitespace(seq.charAt(i))) { return true; } } return false; } /** * <p>Checks if a CharSequence is empty ("") or null.</p> * <p> * <pre> * StringUtils.isEmpty(null) = true * StringUtils.isEmpty("") = true * StringUtils.isEmpty(" ") = false * StringUtils.isEmpty("bob") = false * StringUtils.isEmpty(" bob ") = false * </pre> * <p> * <p>NOTE: This method changed in Lang version 2.0. * It no longer trims the CharSequence. * That functionality is available in isBlank().</p> * * @param cs the CharSequence to check, may be null * @return {@code true} if the CharSequence is empty or null * @since 3.0 Changed signature from isEmpty(String) to isEmpty(CharSequence) */ public static boolean isEmpty(final CharSequence cs) { return cs == null || cs.length() == 0; } }