Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static boolean isNumeric(String string) {
- return string
- .chars()
- .allMatch(x -> '0' <= x && x <= '9');
- }
- static int[] veryGeneralFunction(List<String> strings) {
- return strings
- .stream() // transform into stream
- .filter(x -> isNumeric(x)) // get only the numeric elements
- .sorted() // sort them
- .mapToInt(x -> Integer.parseInt(x)) // transform each element to int
- .toArray(); // make an array
- }
- public static void main(String[] args) {
- List<String> strings = Arrays.asList("123", "a", "0", " ", "999", "9a9");
- for (int i : veryGeneralFunction(strings)) {
- System.out.println(i);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement