SyntaxFix
Write A Post
Hire A Developer
Questions
You can use regex and delete non-digits.
str = str.replaceAll("\\D+","");