我对字符串函数有点困惑 我有一个字符串数组 示例
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/