gpt4 book ai didi

java - .contains 的对面(不包含)

转载 作者:IT老高 更新时间:2023-10-28 20:21:28 26 4
gpt4 key购买 nike

我有一个 if 语句:

if (inventory.contains("bread"))

但现在我想检查一下

  • 如果 inventory 包含“面包”
  • 但不含“水”。

我该怎么做?

最佳答案

Luiggi Mendozajoey rohan 似乎都已经回答了这个问题,但我认为可以澄清一点。

您可以将其编写为单个 if 语句:

if (inventory.contains("bread") && !inventory.contains("water")) {
// do something
}

关于java - .contains 的对面(不包含),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15730134/

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