Skip to content

Commit

Permalink
add consumer
Browse files Browse the repository at this point in the history
  • Loading branch information
lightClouds917 committed Nov 5, 2019
1 parent 8695c65 commit 7d15de1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/test/java/com/java4all/ConsumerTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.java4all;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -14,8 +17,19 @@ public class ConsumerTest {

@Test
public void test(){
List<Integer> list1 = new ArrayList<>();
list1.add(1);
list1.add(3);
list1.add(7);
list1.add(19);
list1.add(20);

foreach(list1,(Integer i)->System.out.println(i));

}

public static <T> void foreach(List<T> list,Consumer<T> consumer){
list.stream().forEach(obj->consumer.accept(obj));
}

}

0 comments on commit 7d15de1

Please sign in to comment.