public class CommandTest { public static void main(String[] args) { ProcessArray processArray = new ProcessArray(); int[] array = new int[]{1,2,3,4,5};
//第一种处理数组的方法 processArray.each(array, new Command() { @Override public void process(int[] target) { for (int cmp:target ) { System.out.println("迭代输出数组元素:"+cmp); } } }); System.out.println("-------------------------------"); //第二种处理数组的方法 processArray.each(array, new Command() { @Override public void process(int[] target) { int sum = 0; for (int tmp:target ) { sum+=tmp; } System.out.println("数组元素的和为:"+sum); } }); } }