is String Empty Or Whitespace Only - Android java.lang

Android examples for java.lang:String Null or Empty

Description

is String Empty Or Whitespace Only

Demo Code

import android.text.TextUtils;
import java.util.ArrayList;
import java.util.List;

public class Main{

    public static boolean isEmptyOrWhitespaceOnly(String str) {
        if (TextUtils.isEmpty(str)) {
            return true;
        }/*from  ww  w .  j a  v  a2  s .c o m*/
        for (int i = 0; i < str.length(); i++) {
            if (!Character.isWhitespace(str.charAt(i))) {
                return false;
            }
        }
        return true;
    }

}

Related Tutorials