java - 从另一个字符串数组中过滤字符串数组

标签 java arrays string java-me

我对字符串函数有点困惑 我有一个字符串数组 示例

String Array1[]=new String[10];
Array1[0]="Hello";

String Array2[]=new String[10];
Array2[0]="Hello my world";
Array2[1]="Hi buddy";

我想从Array2中过滤字符串Array1[0] 即字符串“Hello”出现在Array2的哪个索引中。

最佳答案

   /**
     * This method searches for key in the array of String , starts looking from fromIndexSpecified
     * @param source
     * @param key
     * @param fromIndex
     * @return
     */
    private static int findIndexOfKey(String[] source, String key, int fromIndex) {

        if (fromIndex > source.length) {
            return -1;// invalid arg ..can also throw IlligleArgumentException
        }
        for (int index = fromIndex; index < source.length; index++) {
            if (source[index].indexOf(key) > -1) {
                return index;//found..!
            }
        }
        return -1; //no match found
    }

关于java - 从另一个字符串数组中过滤字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5819575/

相关文章:

Java 从套接字读取消息未发送完整消息

python - 在 Python 的 NumPy 中创建数组时方括号和括号之间的区别

python - 如何使用正则表达式提取文本 block 而不将文本 block 分成几行

Python:在字符串中查找模式

java - 如何使周期性事件在 AsyncTask 的 doInBackground 中的每个周期性间隔运行

java - 在通过 wildfly 将实体持久化到 postgresql 期间挂起的多线程事务

java - 强制子类重写以自身为参数的方法

javascript - 如何使用 JavaScript 将带有参数的 URL 字符串拆分为数组

javascript - 使用 foreach 循环遍历表创建数组

python - Python 有流式正则表达式模块吗?