Tuesday, 3 September 2013

Readable way to concat many strings in java

Readable way to concat many strings in java

I have some code written in a very cryptic fashion. It is sure going to be
a maintenance nightmare for anyone other than me to understand.
Its a mishmash of string concatenation, ternary operator and concatenating
using + operator.
So my question is how would I make this statement readable?
tb.setTally_narration(tb.getTally_mode().equals("Ca")? "Receipt No.
".concat(tb.getTally_receipt_no()).concat(", "+tb.getTally_mode()) :
"Receipt No. ".concat(tb.getTally_receipt_no()+",
"+tb.getTally_mode()).concat(", "+tb.getTally_instrument_no()+",
"+tb.getTally_instrument_date()+", "+tb.getTally_instrument_bank()));

No comments:

Post a Comment