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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:28:23+00:00 2026-06-07T04:28:23+00:00

public String getPreviewMessageForWebdavResponse(){ String format=<preview><currentNumber>%d</currentNumber><totalNumber>%d</totalNumber></preview>; return String.format(format, currentNumber,totalNumber); } Sometimes, I encounter a string.

  • 0
public String getPreviewMessageForWebdavResponse(){ 

    String format="<preview><currentNumber>%d</currentNumber><totalNumber>%d</totalNumber></preview>";
    return String.format(format, currentNumber,totalNumber);
}

Sometimes, I encounter a string. I can’t judge if it needs to be a constant or local var. The String is only used once in the method and need not be exposed outside the method.

How to choose?

  • 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-07T04:28:25+00:00Added an answer on June 7, 2026 at 4:28 am

    Your question is a bit unclear. I will answer the three possible question that come to mind:

    (all of them are questions of style only).

    Should I use a variable at all, or just inline the String literal into the one place it is used?

    I’d say, at least in your case, where the sheer length of the String suggests this, keep it as a variable with a descriptive name, and keep it at the top of the method. Makes it easier to find and update later if necessary, makes it easier to refactor if you do need it more than once later, makes it easier to read.

    Should the variable be local and final?

    Probably.

    Should it be a class-level constant (static final)?

    Always keep scope and visibility as limited as possible.

    If it is only used in the one method, keep it in the method.

    If it is used in multiple methods in the same class, make it private static final.

    If it is used in multiple places in the same package, make it static final.

    If it is used throughout the project, only then make it public.

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

Sidebar

Related Questions

public string Format { get { return string.Format({0}{1}v{1}, LastManStanding ? FFA : string.Empty, m_Teams.PlayersPerTeam);
public String format() { return printf(%1$10s, %2$10s, %3$10d, getForename(), getSurname(), getAge()); } I'm trying
public class Account { public string Username { get { return Username; } set
public String starString(int n){ int m = (int)Math.pow(2,n); String str=; str = starString(m-1,str); return
public String getSubscriberId(){ operator = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); String IMSI = operator.getSubscriberId(); return IMSI; } simID
public string MyMethod(string param1) { var url = string.Format(UrlMask, HttpUtility.UrlEncode(param1), Login, ApiKey); HttpWebRequest request
public string Source { get { /* if ( Source == null ){ return
Code: public String get() { try { //doSomething return Hello; } finally { System.out.print(Finally);
public class A { public virtual string Go(string str) { return str; } }
public string AgentVersion { get { return m_version; } } // property: Enabled private

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.