Suppose you know the indexes i1, i2 of a
string that define a substring, but you don't know which comes first
is there any other way besides the following
if( i1 < i2 ) {
return s.substring(i1,i2);
}
else return s.substring(i2,i1);
or
return s.substring( Math.min(i1,i2), Math.max(i1,i2) );
is one of these better that the other? Since it is an operation that conceivably can be performed many millions of times, CPU cycles is an issue. I could set up a
test I suppose, but I'm curious what people have to say about it.
or return (i1<i2) ? s.substring(i1,i2) : s.substring(i2,i1);
thanks.
>