import java.util.*; class Ideone { public static void main (String[] args) { String str = "asdsad 59 asdf .2 asdf 56 89 .a 2.4 wef 95 asdf."; String[] parts = str.split("([^\\d.]|\\B\\.|\\.\\B)+"); System.out.println( Arrays.toString( parts)); double[] numbers = Arrays.stream(str.split("([^\\d.]|\\B\\.|\\.\\B)+")) .filter(s -> !s.isEmpty()) .mapToDouble(Double::parseDouble) .toArray(); System.out.println( Arrays.toString( numbers)); }}
Standard input is empty
[, 59, 2, 56, 89, 2.4, 95] [59.0, 2.0, 56.0, 89.0, 2.4, 95.0]
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!