'Why doesn't Integer.parseInt work on a substring?

This conversion is not working, I am getting an exception, not sure why

    String str = "Draw: 1";
    int draw = 0;
    String temp;
    temp = str.substring(5,7);
    draw= Integer.parseInt(temp);
    System.out.println(draw);


Solution 1:[1]

Because you're trying to parse " 1", notice the space. Adding a trim() should solve it.

temp = str.substring(5,7).trim();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 crimson589