import java.util.ArrayList;
import java.util.List;
public class javaStreamExamples {
List<String> list1=new ArrayList<>();
public void testStream(){
list1.add("Test");
list1.add("Testing");
list1.add("Selenium");
list1.stream().filter(s->s.contains("Test")).forEach(System.out::println);
}
}
O/p
Test
Testing
==================================================
2) Find duplicate number in given integer using string
import java.util.ArrayList;
import java.util.List;
public class javaStreamExamples {
List<Integer> list1=Arrays.asList(10,20,35,20,67,10)
public void testStream(){
Set<Integer> set1= new HashSet();
list1.stream().filter(s->!set1.add(s)).forEach(System.out::println);
}
}
O/p
import java.util.List;
public class javaStreamExamples {
List<Integer> list1=Arrays.asList(10,20,35,20,67,10)
public void testStream(){
Set<Integer> set1= new HashSet();
list1.stream().filter(s->!set1.add(s)).forEach(
}
}
O/p
10
20
==================================================
No comments:
Post a Comment