编一个JAVA程序,字符串数组中查找一个指定的字符串。

1、定义一个查找方法。2、主方法中定义数组初始化。
2024年12月02日 08:27
有3个网友回答
网友(1):

List list = SearchL;
String s1 = list.getString(list.getSelectedIndex());
int i1 = s1.lastIndexOf(':', s1.length());
String s4 = s1.substring(i1 + 1, s1.length());
int j1 = Integer.parseInt(s4, 10);
DrawStr.cline = j1;
GuoCPU.setCurrent(BackDis);
DrawStr.cline = j1;
} else
if (OpenFun == 2)
{
List list1 = SearchL;
int k = list1.getSelectedIndex();
String s2 = list1.getString(list1.getSelectedIndex());
String s5 = s2.substring(0, 3);
System.out.println("285241331= " + s5);
int k1 = Integer.parseInt(s5) - 1;
System.out.println("filej1= " + k1);
System.out.println("搜索文本FilePaths[filej-1]=" + FilePaths[k1]);
GuoCPU.ExplorerFile(FilePaths[k1]);
}
} else
if (command == CyberSearch)
{
Search_Str = Search_TextFiled.getString();
int j = Search_CH.getSelectedIndex();
if (j == 0)
{
System.out.println("搜索文本");
SearchL.deleteAll();
SearchS(Res_StrS, Search_Str, 0, Res_StrS.length - 1);
} else
if (j == 1)
{
System.out.println("搜索文件");
详情:http://xzf.2000y.net/mb/1/ReadNews.asp?NewsID=565283

网友(2):

String tmp = "tmp:
for(String str: strs){
if(tmp.equals(str)){
//....
}
}

网友(3):

public class Test{

public static void main(String args[]){

String[] strArys = new String[3];
strArys[0] = "1111";
strArys[1] = "2222";
strArys[2] = "33333";

String searchStr = "2222";

boolean isStringFound = searchStringInArray(strArys, searchStr);

System.out.println(searchStr + " found in strArys? " + boolean);

}

public static boolean searchStringInArray(String[] strAry, String searchStr){

boolean isStringFound = false;

for(String str: strAry){

if(searchStr.equals(str)){
isStringFound = true;
break;
}

}

return isStringFound;

}

}