Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8327119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:59:50+00:00 2026-06-09T00:59:50+00:00

May be simple question but i am confused which code is optimized ? and

  • 0

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());
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:59:52+00:00Added an answer on June 9, 2026 at 12:59 am

    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 :

    String str = editText.getText().toString();     
    str = str.trim().toLowerCase();
    textView.setText(str);
    

    compiles to :

           0: aload_0       
           1: getfield      #7                  // Field textView:Landroid/widget/TextView;
           4: aload_0       
           5: getfield      #4                  // Field editText:Landroid/widget/EditText;
           8: invokevirtual #8                  // Method android/widget/EditText.getText:()Landroid/text/Editable;
          11: invokevirtual #9                  // Method java/lang/Object.toString:()Ljava/lang/String;
          14: invokevirtual #10                 // Method java/lang/String.trim:()Ljava/lang/String;
          17: invokevirtual #11                 // Method java/lang/String.toLowerCase:()Ljava/lang/String;
          20: invokevirtual #12                 // Method android/widget/TextView.setText:(Ljava/lang/CharSequence;)V
          23: return        
    

    and the second one :

    textView.setText(editText.getText().toString().trim().toLowerCase());
    

    gives the following result :

           0: aload_0       
           1: getfield      #7                  // Field textView:Landroid/widget/TextView;
           4: aload_0       
           5: getfield      #4                  // Field editText:Landroid/widget/EditText;
           8: invokevirtual #8                  // Method android/widget/EditText.getText:()Landroid/text/Editable;
          11: invokevirtual #9                  // Method java/lang/Object.toString:()Ljava/lang/String;
          14: invokevirtual #10                 // Method java/lang/String.trim:()Ljava/lang/String;
          17: invokevirtual #11                 // Method java/lang/String.toLowerCase:()Ljava/lang/String;
          20: invokevirtual #12                 // Method android/widget/TextView.setText:(Ljava/lang/CharSequence;)V
          23: return        
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may be a simple question, but I am stuck: I want to use
This may be a simple question but I can;t find the answer anywhere. Here
This may be very simple question,But please help me. i wanted to know what
Okay this may be a simple question but I have yet to come with
may be too simple groovy question but....please help i have a list like this:
May be its a simple question but it's really driving me crazy. I just
This may seem like a simple question but i am getting an error when
I'm fairly new to Android programming, so this may be a simple question, but
this may be a very simple question, but is it possible to force a
I know this may be simple question but want to know every ones opinion

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.