gpt4 book ai didi

Java字符串数组: how do I check if the array has a value?

转载 作者:行者123 更新时间:2023-12-01 13:20:46 26 4
gpt4 key购买 nike

我正在用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com