如何检查字符串数组为空或空的Andr​​oid?数组、字符串、为空、oid

2023-09-12 09:54:27 作者:人間太苦了.

我是新来的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 返回不是空[你也可以在退房前长度丢弃空白修剪]。

一些相关的热门问题的 -

什么是Java的空? 避免!= NULL的Java语句?

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 -

What is null in java? Avoiding "!= null" statements in Java?