This is pretty much impossible without at least one loop and at least one if condition (maybe two) inside the loop. Or maybe a ternatry operator instead of an if, but the difference seems immaterial. You could hide the loop and conditions by putting them in a separate method - or by calling a pre-existing method such as Arrays.sort() as Paul suggests. But the loop will have to exist somewhere, regardless.