import java.lang.reflect.Method;
import java.util.regex.Pattern;
/**
 * @author Tower
 * @version Sep 9, 2008 9:25:42 AM
 */
public abstract class Debug {
    public static boolean m1(Object str){
        Pattern pattern = Pattern.compile("[0-9]*");
        System.out.println("------------------m1");
        return pattern.matcher(str.toString()).matches();  
    }
    public static boolean m2(String str){
        System.out.println("------------------m2");
        return (str.length()> 3);
    }
    public static boolean m3(String str){
        System.out.println("------------------m3");
        return (str.endsWith("xml"));
    }
    public static boolean m4(String str,String length){
        System.out.println("------------------m4");
        return (str.length() < Integer.parseInt(length));
    }
    public static void main(String args[]){
        try {
            Method [] methods = Debug.class.getMethods();
            for(Method me : methods){              //有如此例
                if(me.getName().toString().equalsIgnoreCase("m4")){
                    System.out.println(me.invoke(null,"7777","4"));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

解决方案 »

  1.   

    迭代methods的每一个元素
    JDK1.5特性
      

  2.   

    JDK5的新特性。for(Method me : methods){  
      ...
    }等同于:for(int i=0;i<methods.length;i++){  
       Method me = methods[i]
       ...
    }
      

  3.   

    还有中for循环
    for(;i<methods.length;i++){
      //
    }
      

  4.   

    for(Method me : methods){              //有如此例
                    if(me.getName().toString().equalsIgnoreCase("m4")){
                        System.out.println(me.invoke(null,"7777","4"));
                    }
                }:后面是一个List Map 数组  
      

  5.   

    这个是jdk1.5新增的功能
    楼上回答正解
      

  6.   

    这是jdk1.5加入的新特性  泛型
      

  7.   

    for(Method me : methods)
         定义一个 Method 类型的变量me 
    methods数组中每个元素
      

  8.   

    以上说的都对
    适用于逐个遍历的情况,即每次一步递增,即for(int i = 0; i < n; i++)的形式
    如果是i = i + 2就不适用了。
      

  9.   

    for(X:Y) X代表什么,Y代表什么答:依次逐个地将Y中的数据放入到X中,如此遍历。
      

  10.   

    这是 jdk 1.5后的新特性,是为了方便容器的便利加入的,
    :前面的代表容器内的element   :后面代表的是容器一般只用在遍历,不用于复杂的操作
      

  11.   

    我天天在进步   超级感谢吗士兵老师和CSDN上的老油条!!~~~~~~~~~
      

  12.   

    X:是一个Y对象类
    Y:是一个集合也可以是一个对象数组还可以是知道数据类型的变量
      

  13.   

    for each循环?  前面是元素,后边是元素所在数组。
      

  14.   

    for(X:Y) X代表什么,Y代表什么??
    X定义一个类型的变量,可以是数组或list
    Y代表你是一个集合的变量,就是你定义的数据或LIST的名字
      

  15.   

    jdk1.5的新功能——增强型for循环,用于遍历集合。相当于for循环
      

  16.   

    for(X:Y)====
    在 Y 中的 每一个 X
      

  17.   

    JDK5的新特性。 for(Method me : methods){ 
    ... 
    } 等同于: for(int i=0;i <methods.length;i++){ 
    Method me = methods[i] 
    ... 

      

  18.   

    呵呵,这个是增强型的for循环哦
      

  19.   

    循环遍历Y中的每一个X,X是为Y中元素的一个别称,相当于新定义的一个变量,把Y中的元素赋值给它~~~
    与jstl标签的for循环有点像
      

  20.   

    x代表一个元素  y代表一个集合或数组相当于c#中的foreach