If you were using string concatenation here you could just do url.endsWith('/') and skip the length check.