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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:11:28+00:00 2026-05-22T16:11:28+00:00

Here is the peace of code, Which I am looking to make it more

  • 0

Here is the peace of code, Which I am looking to make it more efficient
I see lots of if else statements,

Can any one help me to make it simple and reduce the number of lines of code

if(mmPageCounter.equalsIgnoreCase("trueNotFull")){
    if(whatPageNext.equalsIgnoreCase("first"))
        accountListSize = 5;
    else
        accountListSize = acctIdList.size();
}else if(mmPageCounter.equalsIgnoreCase("true")){
    if(whatPageNext.equalsIgnoreCase("first"))
        accountListSize = 5;
    else
        accountListSize = 10;
}else if(mmPageCounter.equalsIgnoreCase("false")){
    if(whatPageNext.equalsIgnoreCase("alwaysFirst"))    
        accountListSize = acctIdList.size();
}

In the above code based on the mmPageCounter based on the value I am setting the
index of the For loop either to the full capactiy, or to the actual value

Full capacity means, The for loop will iterate only 10 items

ps : I have got the code working and its fine, But i am looking only for the fine tuning

If any one one has any fine tuning tips please share the links.

  • 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-22T16:11:28+00:00Added an answer on May 22, 2026 at 4:11 pm

    This does not make it faster but reduces code, you can substitute:

    if(whatPageNext.equalsIgnoreCase("first"))
        accountListSize = 5;
    else
        accountListSize = 10;
    

    by:

    accountListSize = whatPageNext.equalsIgnoreCase("first") ? 5 : 10;
    

    and:

    if(whatPageNext.equalsIgnoreCase("first"))
        accountListSize = 5;
    else
        accountListSize = acctIdList.size();
    

    by:

    accountListSize = whatPageNext.equalsIgnoreCase("first") ? 5 : acctIdList.size();
    

    UPDATE:

    If mmPageCounter can only be “trueNotNull”, “true”, or “false” then I think this code is equivalent:

    int maxsize = mmPageCounter.equalsIgnoreCase("true") ? 10 : acctIdList.size();
    
    if(mmPageCounter.equalsIgnoreCase("false")){
        if(whatPageNext.equalsIgnoreCase("alwaysFirst"))    
            accountListSize = accountListSize = acctIdList.size();
    } else {
      accountListSize = whatPageNext.equalsIgnoreCase("first") ? 5 : maxsize
    }
    

    but you should write tests against current code and check that this code behaves exactly in the same way on edge cases.

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

Sidebar

Related Questions

first post here, I come in peace :) I've searched but can't quite find
Here is my code, which takes two version identifiers in the form 1, 5,
I am looking for a basic pattern where I can move some shared code.
I'm looking at some existing code that is generating a salt which is used
I am looking for the simplest example which shows one window opening another window
I happen to come across a Java code at my work place. Here's the
MSSQL 2008 Maybe i'm just looking in the wrong place. Here's the scenario: We
I'm looking for a voting system that we can implement at work amongst our
I'm particularly interested in Windows PowerShell , but here's a somewhat more general complaint:
I have code in the following form in which the user may specify a

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.