This works pretty well for certain cases, namely if there is at least 2 or more trailing spaces, it works great.
i.e. "myid      "

However, it does seem to fail for a single extra space, such as "myid ".  Try taking a look at substring() and whether or not the start and end are inclusive or exclusive.

Also, as a bonus, do you want to consider leading whitespace?  With your approach, a string like " myid" will actually get turned into the empty string "" !

The reason I bring this up is, there does exist a String function that can remove both leading and trailing whitespace in one function call, String.trim().  See if that helps your solution!