怎么判断一个字符串是不是在另一个字符串中?例如a='asfad-12ds',b='-',怎么判断b是不在在a中?

解决方案 »

  1.   


        private static boolean test() {
            String test = "asfad-12ds";
            if(test.contains("-")){
                return true;
            }
         return false;
        }
      

  2.   

    上面那个写的不好,改进一下private static boolean test() {
            String test = "asfad-12ds";
            return test.contains("-");
        }
      

  3.   

    import java.util.regex.*;class Regex1{
     public static void main(String args[]) {
      String a= "asfad-12ds";
      String b="-"; 
      Pattern p=Pattern.compile(b);
      Matcher m=p.matcher(a);
      boolean result=m.find();
      System.out.println(result);
     }

    正则表达式