Do not think that if you put everything on one line, it will be better than if you split the statement into several lines. Typically, the Java compiler is smart enough to create the same bytecode in both cases. Modern compilers do a lot of micro-optimizations.
You can check if there is a difference by compiling them, then decompile the bytecode using the javap -c
command.
Edit:
I just tested and here are the results:
String str = editText.getText().toString(); str = str.trim().toLowerCase(); textView.setText(str);
compiles:
0: aload_0 1: getfield
and second:
textView.setText(editText.getText().toString().trim().toLowerCase());
gives the following result:
0: aload_0 1: getfield
As you can see, I understood correctly that they are identical. The java compiler optimized the first example and completely deleted the variable, since it was useless.
So, conclude that you should use code that you find more readable.
source share