没有见过match(),是不是matcher()?public Pattern.matcher(CharSequence input) 得到一个要比较字符序列是input的比较器(matcher) 
public static boolean Pattern.matches(String regex,CharSequence input)
在字符序列input查找正则表达式regex对应的pattern,
等同与Pattern.compile(regex).matcher(input).matches();
如果regex要使用多次,请使用下面的形式,可以省去编译regex的时间
Pattern partn = Pattern.compile(regex);
partn.matcher(input).matches();

解决方案 »

  1.   

    谢谢cfsego(陈传文) 的回答,String类下有个matches(String regex) 方法,我不知道怎么才能正确使用它.我的本意是,在文本框输入15位数字,然后点按纽jb1,如果是全数字那么在后台打印出输入的字符串,
    如果输入的不是全数字,那么在后台打印"输入的号码位数不正确!"
    我不清楚这个matches(String regex)该怎么正确使用.
    现在的情况是输入超过8位数就会执行ELSE部份的语句.TextField tf  = new TextField();
    //一个按纽临听器.
    jb1.addMouseListener(new MouseAdapter(){
    public void mousePressed(MouseEvent e){
    a=tf.getText();   //得到文本输入框的字符串(15位的字符串).
    if (a.matches("[0-9]{1,8}"))
    {
         System.out.print(a);
    }
    else
                      {        ystem.out.print("输入的号码位数不正确!");
    }
      }
         });
      

  2.   

    再问一下,有没有函数可以在一个字符串的任意位置插入字任串?
    而不是把一个字符串从要插入的位置做为分界线,用比如substring反回两个字符串,然后在再把它们接起来.谢谢.
      

  3.   

    没有
    out = input.substring(0,i).concat(insert).cancat(input.substring(i));