Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (3.9k points)

I have a Java String object. I need to extract only digits from it. I'll give an example:

"123-456-789" I want "123456789"

Is there a library function that extracts only digits?

Thanks for the answers. Before I try these I need to know if I have to install any additional llibraries?

1 Answer

0 votes
by (46k points)

You can use regex and delete non-digits.

str = str.replaceAll("\\D+","");

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Nov 26, 2019 in Java by Nigam (4k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...