I have two List<T>
s of the same T
and a T
object. Based on a condition, I want to add the object to one of the two lists. So I did:
(condition ? listOne : listTwo).add(item);
To me, this is great, because it cuts a 5-line snippet:
if (condition) {
listOne.add(item);
} else {
listTwo.add(item);
}
...or a (less readable, IMO) 2-line snippet:
if (condition) listOne.add(item);
else listTwo.add(item);
...to one line. But is it bad practice?