如何检查字符串数组为空或空的Andr​​oid? [英] how to check the string array is empty or null android?

查看:160
本文介绍了如何检查字符串数组为空或空的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Java。我无法检查空。你能见识一下呢? 我有字符串数组有没有元素。

我想这code

 的String [] K =新的String [3];
如果(K == NULL){
    的System.out.println(k.length);
}
 

解决方案

非常precisely

 如果(K = NULL和放大器;!&安培; k.length> 0){
    的System.out.println(k.length);
}其他
    的System.out.println(阵列未初始化或为空);
 

K!= NULL 将检查阵列不是。而字符串数组#长度大于0 返回不是空[你也可以在退房前长度丢弃空白修剪]。

一些相关的热门问题的 -

I am new to java. Am unable to check for null. Could you enlighten me on this? I have string array which has no elements.

I tried this code

String[] k = new String[3];
if(k==null){
    System.out.println(k.length);
}

解决方案

Very precisely

if(k!=null && k.length>0){
    System.out.println(k.length);
}else
    System.out.println("Array is not initialized or empty");

k!=null would check array is not null. And StringArray#length>0 would return it is not empty[you can also trim before check length which discard white spaces].

Some related popular question -

这篇关于如何检查字符串数组为空或空的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆