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 6860969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:28:32+00:00 2026-05-27T02:28:32+00:00

I use some strings which are defined in a resource file. What is better

  • 0

I use some strings which are defined in a resource file. What is better in terms of resource usage and performance?
Call context.getString(stringId) every single loop or store the context.getString(stringId) in a variable outside of the loop and use this variable within the loop.

Some pseudocode …

Without a variable:

while (condition) {
   DoSomethingWithString(context.getString(stringId));
}

With a variable:

String variable = context.getString(stringId);
while (condition) {
   DoSomethingWithString(variable);
}

Some more thoughts … the variable stuff looks like to be the better solution because there is no need to fetch the data from the resource file every time. But you have to use one more variable. OK, it’s just one variable in this case but it’s also only a pseudo example so it could maybe add some resource usage. Beside this the resourcestring have to copied to another string before this string is used (performance?).
The usage of context.getString(stringId) within a loop could be the better solution when the bytecode compiler does a good optimizing job.

  • 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-05-27T02:28:33+00:00Added an answer on May 27, 2026 at 2:28 am

    (As per my understanding of your question) I advise you to store the context.getString(stringId) in a variable outside of the loop and use this variable within the loop.

    Because, In this, in for loop your program executer doesn’t need to go every time to fetch data from String file. It just refer the single variable.

    For example:

    String result = context.getString(id);
    
    for(int i=o;i<some.size();i++)
    {
     Log.d(TAG, result);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Kettle, I use the following logic in a transformation, given some Strings X
I am developing an application which has defined some intent filters (in the form
I use Spring along with Hibernate. In my DAO, I defined a NamedQuery which
I could use some help creating an XSL template that will take a string
I'd like to use a Regex parser to aid in some string processing in
Can I simply use if(myString == nil) For some reason a string that I
I have some html extracted to a string var, and want to then use
Traditionally, when we use SQL string to done some work, we have to close
I have a Java string of XML content. I use Velocity to generate some
I use some HTTP Handlers from my Web Forms days forms, to for example

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.