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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:30:41+00:00 2026-06-15T13:30:41+00:00

inside my java programm I need to have a control-structure which should give 3

  • 0

inside my java programm I need to have a control-structure which should give 3 different outcomes to 3 different inputs.

Input 1: Text 1

Input 2: Text 2

Input 3: Text 3

My Question here is: Best-Practice wise and efficiency wise, which control structure should be used? My First thought has been a switch case, but why would I choose that over IF-Structures or nested ? operators??

  • 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-15T13:30:42+00:00Added an answer on June 15, 2026 at 1:30 pm

    I think you’ll find it generally agreed that the switch statement is mildly preferred in this situation, purely on the basis of readability. It scales a lot better if additional cases are added and even with three options, it’s still a bit more readable, particularly with the cases being simply three variations of one input. Performance differences are negligible but there are surely discussions out there if you really want to get into that specific aspect.

    I’d suggest avoiding the ternary operator (i.e., inline if/’?’) for any more than two cases for similar reasons of readability. Personally, I don’t parse it as well and I avoid it unless all expressions involved are very brief.

    Mostly off-topic, but interestingly, switching on Strings wasn’t added to Java til Java 7.

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

Sidebar

Related Questions

I need to construct a file path inside a java program. Which path separator
I have a jsp page which needs a java code. This java code inside
I need an Android application which should be able to fetch data from the
I have a java program which emulates a car fabric. I wrote an explanation,
I need to clean up Html5 pages inside my Java project. So I need
I have a JSP form which is made of <input type=file/> tag alone for
I am trying to run cut inside a java program, but I am lost
I was wondering how to run some JUnit4 test inside a java program. Basically
I am trying got use spring-mvc tag inside java-script file, here is what i
I've got a problem where calling grep from inside java gives incorrect results, as

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.