gpt4 book ai didi

java - 从数组中的字符串获取索引

转载 作者:行者123 更新时间:2023-12-01 22:20:14 24 4
gpt4 key购买 nike

我有一个像这样的数组: String[] articles = {"a", "and", "the"};我想知道如何从某个术语获取数组索引。有没有类似于 articles.getIndex("the"); 的方法它会返回一个 int (在本例中为 2)?

最佳答案

您可以创建包装数组的 List 并使用其 indexOf 方法

Arrays.asList(yourArray).indexOf(element)

关于java - 从数组中的字符串获取索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30003856/

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