gpt4 book ai didi

java - 根据字符串搜索 Java 集合

转载 作者:行者123 更新时间:2023-12-02 08:24:59 24 4
gpt4 key购买 nike

我有一个具有以下结构的集合...

ArrayList<String[]> schools = new ArrayList<String[]>();

我还有一个字符串“United Berkley”

现在我想在“schools”中搜索上述字符串,如果String[]<中有任何匹配项,则返回String[]/strong> 数组。

我有基本的代码,但找不到所需的正则表达式

String target = this.Schools.get(s)[a];
if (target.matches("*")) {
schools.add(this.Schools.get(s));
}

最佳答案

您的schools数据结构看起来有点……奇怪。

你确定你想要的不是 ArrayList<String>

如果是这种情况,那么您可以使用:

if (schools.contains("United Berkley"))

关于java - 根据字符串搜索 Java 集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4701312/

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