Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Check if there are numbers in a string in Java

edited March 2018 in Android

I am developing a webView android application that embedded actual a Vanilla forum.I want to interact from one post to another using button at the bottom of NavigationView.I want to read the current url format it and open a new url in previous and next buttons.

Sample url =

How do i read that url and get only the number 72.

Help guys


  • Actually, i was able to work this out.Below code worked fine for me
    * @author Eric
    public class StringExample {

    public StringExample()
    String s=extractNumber("");
    int i=Integer.parseInt(s);
    public  String extractNumber( String str) {                
    if(str == null || str.isEmpty()) return "";
    StringBuilder sb = new StringBuilder();
    boolean found = false;
    for(char c : str.toCharArray()){
            found = true;
        } else if(found){
            // If we already found a digit before and this char is not a digit, stop looping
    return sb.toString();


    public static void main(String args[])

    new StringExample();


Sign In or Register to comment.