Sorting Strings by Character and Length
<p>In my Android app, I am trying to sort Bus route tags in order 1, 2, 3..etc.</p>

<p>For that I am using this</p>

<pre><code>Collections.sort(directions, Comparator { lhs, rhs -&gt;
        var obj1 = lhs.short_names.firstOrNull() ?: ""
        var obj2 = rhs.short_names.firstOrNull() ?: ""

        if (obj1 === obj2) {
            obj1 = lhs.headsigns.firstOrNull() ?: ""
            obj2 = rhs.headsigns.firstOrNull() ?: ""
            if (obj1 === obj2) {
                return@Comparator 0
            }
            obj1.compareTo(obj2)
        } else {
            obj1.compareTo(obj2)
        }
</code></pre>

<p>The issue I am having is this sorts them, but will run into the issue of
1, 2, 3, 30, 31, 4, 5</p>

<p>How should I change this to get the correct ordering. </p>