Java-在if语句中搜索我的数组列表以查看它是否包含名称
基本上,我希望这段代码只在项目在库存中时执行,现在它一直执行。我不知道在if语句中放什么,因为我所做的一切只是使currentMessage等于它以前的值Java-在if语句中搜索我的数组列表以查看它是否包含名称,java,if-statement,arraylist,boolean,Java,If Statement,Arraylist,Boolean,基本上,我希望这段代码只在项目在库存中时执行,现在它一直执行。我不知道在if语句中放什么,因为我所做的一切只是使currentMessage等于它以前的值 public void read(){ boolean found = myArray.contains("textBooks"); currentMessage = "sorry you cannot read this text book because you are not the all knowing"; }
public void read(){
boolean found = myArray.contains("textBooks");
currentMessage = "sorry you cannot read this text book because you are not the all knowing";
}
我还建议看一下这里的java基础知识这就是我所拥有的,但它从不显示currentMessage
System.out.println(currentMessage)代码>您尝试过侦听器吗?没有,我没有尝试过。我会在资源清册上设置一个侦听器,每当资源清册内容更改时,该侦听器都会运行此代码。。。
if(myArray.contains("textbooks"))
currentMessage = "You may read"
else
currentMessage = "You may not read"