May be simple question but i am confused
which code is optimized ? and should i use ?
what is the difference in internal process ?
String str = editText.getText().toString();
str =str.trim().toLowerCase();
textView.setText(str);
textView.setText(editText.getText().toString().trim().toLowerCase());
Don’t think that if you put everything on a single line, it will be better than if you split the statement in multiple lines. Generally the Java compiler is smart enough to produce exactly the same bytecode in both cases. Modern compilers do a lot of micro-optimizations.
You can check if there’s a difference by compiling them, then decompile the bytecode with the command
javap -c.Edit :
I just tested and here are the results :
compiles to :
and the second one :
gives the following result :
As you can see I guessed right, they are identical. The java compiler optimized the first example and completely removed the variable as it was useless.
So the conclusion is that you should use the code that you find the more readable.