【问题标题】:Java - searching my array list in an if statement to see if it contains a nameJava - 在 if 语句中搜索我的数组列表以查看它是否包含名称
【发布时间】:2014-12-01 01:44:54
【问题描述】:

基本上,我希望此代码仅在物品 textBooks 在库存中时执行,现在它一直执行。我不知道该在 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";

} 

【问题讨论】:

  • 你试过监听器了吗?
  • 不,我没试过
  • 我会在库存上设置一个监听器,每次库存内容更改时都会运行此代码...

标签: java if-statement arraylist boolean


【解决方案1】:
if(myArray.contains("textbooks"))
    currentMessage = "You may read"
else
    currentMessage = "You may not read"

我还建议在这里查看 java 基础知识http://docs.oracle.com/javase/tutorial/java/nutsandbolts/

【讨论】:

  • 这是我的,但它从不显示当前消息
  • System.out.println(currentMessage);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-13
  • 2020-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多