(String[] args)
| 19 | .forEach(System.out::println); |
| 20 | } |
| 21 | public static void main(String[] args) { |
| 22 | |
| 23 | test("add brackets", s -> "[" + s + "]"); |
| 24 | |
| 25 | test("Increment", s -> { |
| 26 | try { |
| 27 | return Integer.parseInt(s) + 1 + ""; |
| 28 | } catch(NumberFormatException e) { |
| 29 | return s; |
| 30 | } |
| 31 | }); |
| 32 | |
| 33 | test("Replace", s -> s.replace("2", "9")); |
| 34 | |
| 35 | test("Take last digit", s -> s.length() > 0 ? |
| 36 | s.charAt(s.length() - 1) + "" : s); |
| 37 | } |
| 38 | } |
| 39 | /* Output: |
| 40 | ---( add brackets )--- |