我正在用 java 编写一个程序,它将使用字符串数组:
String[] category = new String[46];
然后我将检查 for 循环中的数组是否已经有值,
for(int checking = 21; checking <= 45 ;checking++) {
if(category[checking]=INSERT_HERE) {
textArea += category[checking] + "\n";
}
}
我应该在 INSERT_HERE 中放入什么?注意:textArea 是一个命名的 JTextArea
。
最佳答案
如果您要检查值是否不为空,请使用
if(category[checking]!=null)
如果您要检查某个特定值,那么
if(category[checking].equals(PARTICULAR_VALUE))
PS:“=”用于赋值,应该使用“==”进行比较。
关于Java字符串数组: how do I check if the array has a value?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22039576/