how can we get digit values from strings?

Simplest way would be to split your string on non-digits i.e.

String s = "1+2*3(30+4/2-(10+2))*2+1";
String[] arr = s.split("\\D+");

This will return an array

[1, 2, 3, 30, 4, 2, 10, 2, 2, 1]

which you can then iterate through and convert to double.

As Rohit pointed out this approach will not work if you have numbers with decimal points or if you want to consider also negative numbers.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top