Skip to content

Commit c3fc5e3

Browse files
committed
Parsing String data into Integer and printing
1 parent b37a5f8 commit c3fc5e3

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package test_knowledge;
2+
3+
import java.util.Arrays;
4+
5+
public class Test30 {
6+
7+
/*
8+
* Parse String into array and print data
9+
*/
10+
public static void main(String[] args) {
11+
String[] str = { "1", "2", "3", "new", "5" };
12+
13+
Arrays.stream(str).filter(Test30::isInteger).mapToInt(Integer::parseInt).forEach(System.out::println);
14+
}
15+
16+
public static boolean isInteger(String s) {
17+
try {
18+
Integer.parseInt(s);
19+
return true;
20+
} catch (NumberFormatException e) {
21+
return false;
22+
}
23+
}
24+
25+
}

0 commit comments

Comments
 (0)