c語言判斷一個數(shù)是否在數(shù)組 判斷一個數(shù)組中是否含有某個字符串?
判斷一個數(shù)組中是否含有某個字符串?是String數(shù)組中查找它的元素包不包含某個字符串?這個就用遍歷就好了。String[] strs = new String[]{"hello","tom","wor
判斷一個數(shù)組中是否含有某個字符串?
是String數(shù)組中查找它的元素包不包含某個字符串?這個就用遍歷就好了。String[] strs = new String[]{"hello","tom","world"}//初始化一個數(shù)組//如果想查找String a ="hello"是不是在這個數(shù)組里可以用下面方法String a ="hello"for(int i = 0i<strs.lengthi ){//利用了字符串自帶的length方法,獲取數(shù)組長度 if(strs[i].equals(a)){//用來判斷字符串是否相等 System.out.println("該數(shù)組中有這個字符串") }}