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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:00:08+00:00 2026-05-12T16:00:08+00:00

What modification would bring to this piece of code? In the last lines, should

  • 0

What modification would bring to this piece of code? In the last lines, should I use more if-else structures, instead of “if-if-if”

if (action.equals("opt1"))
{
    //something
}
else
{
    if (action.equals("opt2"))
    {
        //something
    }
    else
    {
        if ((action.equals("opt3")) || (action.equals("opt4")))
        {
            //something
        }
        if (action.equals("opt5"))
        {
            //something
        }
        if (action.equals("opt6"))
        {
            //something
        }
    }
}

Later Edit: This is Java. I don’t think that switch-case structure will work with Strings.

Later Edit 2:

A switch works with the byte, short,
char, and int primitive data types. It
also works with enumerated types
(discussed in Classes and Inheritance)
and a few special classes that “wrap”
certain primitive types: Character,
Byte, Short, and Integer (discussed
in Simple Data Objects ).

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

    Even if you don’t use a switch statement, yes, use else if to avoid useless comparison: if the first if is taken, you don’t want all others ifs to be evaluated here since they’ll always be false. Also you don’t need indenting each if making the last block being so indented that you can’t see it without scrolling, the following code is perfectly readable:

    if (action.equals("opt1")) {
    }
    else if (action.equals("opt2")) {
    }
    else if (action.equals("opt3")) {
    }
    else {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to be able to change a file's modification date for use
What logging library or approach would you recommend for this case: We want to
I am confused between the term file modification time and file changed time. Can
If user input is inserted without modification into an SQL query, then the application
I have a version number of the following form: version.release.modification where version, release and
I was asked to find a way to monitor changes (modification, renaming, deletion, moving)
I would like to make an async GET request that returns back a document
I've heavily edited this question because responses indicated I wasn't being clear problem: UI
If there are extensive modifications made to search.aspx in SPS 2003, will they get
After making a few modifications to a rails app I am tinkering on, railroad

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.