Skip to content

Commit 62b904e

Browse files
committed
added StreamDemo5 class
1 parent 6b5824e commit 62b904e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package java8.stream;
2+
3+
import java.util.regex.Matcher;
4+
import java.util.regex.Pattern;
5+
import java.util.stream.Stream;
6+
7+
/**
8+
*
9+
* @author saurav
10+
*
11+
*/
12+
public class StreamDemo5
13+
{
14+
public static void main(String[] args)
15+
{
16+
17+
Stream.of("a1", "aa", "a3")
18+
.map(a->findInt(a))
19+
.forEach(System.out::println);
20+
}
21+
22+
private static Integer findInt(String s)
23+
{
24+
Matcher m=Pattern.compile("[0-9]+").matcher(s);
25+
if(m.find())
26+
{
27+
return Integer.parseInt(m.group());
28+
}
29+
return null;
30+
}
31+
}

0 commit comments

Comments
 (0)