Indicates whether the characters in a specified string is categorized as white space. - Android java.lang

Android examples for java.lang:Character

Description

Indicates whether the characters in a specified string is categorized as white space.

Demo Code

import java.util.Random;

public class Main{

    /**/*  ww  w. ja v  a 2 s  .  co m*/
     * Indicates whether the characters in a specified string is categorized as
     * white space.
     * 
     * @param s
     *            string.
     * @return true if the characters in s is white space; otherwise, false.
     */
    public static boolean isWhitespace(String s) {
        int length = s.length();
        if (length > 0) {
            for (int i = 0; i < length; i++) {
                if (!Character.isWhitespace(s.charAt(i))) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }

}

Related Tutorials