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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:41:01+00:00 2026-05-16T07:41:01+00:00

Hi, I have 20 strings, each of which will have same package structure except

  • 0

Hi, I have 20 strings, each of which will have same package structure except for the class name. These strings need to be passed to method as required. Refer to the code below:

public static final String RECENT_MSG_        = "com.foo.xxs.RecentMessage";
public static final String PROJ_              = "com.foo.xxs.Proj";
public static final String FORECAST           = "com.foo.xxs.Forecase";
public static final String REQUEST            = "com.foo.xxs.Request";
public static final String UNAPPROVED         = "com.foo.xxs.UnApproved";
public static final String UNPOSTED           = "com.foo.xxs.Unposeted";
public static final String VACANT             = "com.foo.xxs.Vacant";
public static final String ORG_VIOL           = "com.foo.xxs.OrgViolation";
public static final String ORG_WARN           = "com.foo.xxs.OrgWarning";
public static final String EMP_VIOL           = "com.foo.xxs.EmpViolation";
public static final String EMP_WARN           = "com.foo.xxs.EmpWarning";    
public static final String TS_WARN            = "com.foo.xxs.TSWarn";
public static final String TS_VIOL            = "com.foo.xxs.TSViolation";
public static final String AGE_GROUP          = "com.foo.xxs.AgeGroup";


private void rescheduleTasks(long _taskType,String value)
{
    if(_taskType == 1000 &&(_sSchedTaskMgr.getInstance().getCurrentScheduledTaskInfo(RECENT_MSG_)==null))
    {

    // do something     
    }

}

This can also be done as follows:

public static final String RECENT_MSG_        = "RecentMessage";
public static final String PACK                       ="com.foo.xxs."

And concatenating the strings like so:

if(_taskType == 1000 &&(_sSchedTaskMgr.getInstance().getCurrentScheduledTaskInfo(PACK+RECENT_MSG_)==null))

Which one would be better?

  • 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-16T07:41:02+00:00Added an answer on May 16, 2026 at 7:41 am

    They will have the same performance – the concatenation will be performed at compile time rather than execution time as both parts are constants. There will be fewer strings in the constant pool in the original version, admittedly – but that’s unlikely to make a difference.

    Which do you find more readable? I can’t say there’s much in it for me – I dislike the repetition of the first form, but equally I’m not sure I’d want to concatenate everywhere.

    Another alternative is:

    public static final String PACK               = "com.foo.xxs."
    public static final String RECENT_MSG_        = PACK + "RecentMessage";
    

    etc – so you perform the concatenation at the point of the constant declaration. Then you can just use RECENT_MSG_ in the code, as per the first snippet, but avoid the “com.foo.xxs” duplication as per the second.

    EDIT: Another option you may want to consider is using an enum.

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

Sidebar

Related Questions

I have sets of strings in a database. Each set will have less than
I have a string which contains binary digits. How to separate string after each
I have a file called messages.properties which has lines with syntax <key>=<string> . Each
I have the list with like 100,000 site link strings Each link is unique,
If I have theses general sql valid dates in c# strings : (each date
I have a bunch of strings that are dependent on static dictionaries and each
I have a For Each loop that is looping through an array of strings
I have a some of html strings that my application generates. Each html 'snippet'
Currently, I have an array of Strings, each with random characters in it that
I have 4 string arrays,each of these array's length is 4. I also have

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.