类型类数组中的布尔方法

时间:2015-09-23 02:46:55

标签: java

我无法编译此方法。此方法是搜索Event类型的数组。因此,如果月份包含[1,2,3,4,5,6,7 *,8,9 *],它将搜索星号并返回true

 public static boolean isSignificant(Event[] month, String SearchValue) 
      {
        boolean isFound = false;
        for(int i = 0; i< month.length && isFound == false; i++)
        {

          if(month[i].contains(SearchValue)) // error on this line
          {
            isFound = true;
          }
        }
        return isFound;
      }

2 个答案:

答案 0 :(得分:1)

搜索此模式的方法有很多种

  1. 09-22 22:35:20.152 5158 5254 E BluetoothUtils: Permission denial: Need ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission to get scan results
  2. if (value.endsWith("*")) {
  3. if (value.matches(".*\\*$")) {
  4. e.g。

    value.matches(".*?\\*$")

答案 1 :(得分:0)

@ Jean-FrançoisSavard是对的,在搜索字符串时,月份属于Event类型。如果你向我解释更多信息,我可以帮助你更多,否则生病只是假设你的意思是一个字符串数组。

public class HelloWorld{

     public static void main(String []args){
        System.out.println("Hello World");
        String [] array = {"1","2","3","4*"} ; 
        if(isSignificant(array,"*")){
            System.out.println("Found");
        }else{
            System.out.println("Not found");
        }
     }

     public static boolean isSignificant(String[] month, String SearchValue) {
        for(int i = 0; i< month.length; i++) {

          if(month[i].contains(SearchValue)) {
            return true;
          }
        }
        return false;
      }
}