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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:23:18+00:00 2026-06-16T19:23:18+00:00

Assuming you want to test if an input is one of several constant Strings,

  • 0

Assuming you want to test if an input is one of several constant Strings, and ignoring performance, is it an anti-pattern to code:

if ("yes oui ja da".contains(answer)) {
    // answer was in the affirmative
}

instead of the more conventional:

private static List<String> affirmativeAnswers = Arrays.asList("yes", "oui", "ja", "da");

if (affirmativeAnswers.contains(answer)) {
    // answer was in the affirmative
}

It’s a lot less code and easier to read, but is it a "hack"?

Edit:

For more safety, if you are worried about partial matches, you can code it as:

if (",yes,oui,ja,da,".contains(',' + answer + ',')) 

It’s still much less code (although getting ugly)

  • 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-16T19:23:19+00:00Added an answer on June 16, 2026 at 7:23 pm

    … is it an abuse of the language …

    “Java – he don’t care!!”. But “Eww!! Nasty!!”1.

    But seriously, you should be aiming to make your code easy to read and easy to maintain. (Or performant … if that matters.)

    Tricky, obscure code that expresses something using the minimum number of keystrokes is none of the above. It is bad style … even if you get the code functionally correct.


    1 – if you’ve been living under a rock for the past year or so … I’m alluding to this – http://knowyourmeme.com/memes/honey-badger.

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

Sidebar

Related Questions

Assuming sr is an IEnumerable<string> , I want to use code like this to
Is this good OO Design assuming you want every inheriting class to be a
Assuming I have a column called A and I want to check if A
assuming that I know the PID of a process and want to do a
Assuming I have a numerical string: var foo = 0; Assume I want to
I want to display a list of complex, but fixed-size multiline elements, assuming that
my question is: assuming we have a calendar_table with UNIX datestamp date_column, i want
so i was doing some algorithm solving problems and the first questions input/output test
i want to test how my application reacts to high -dpi settings. i don't
I want to test which data structure is the best by looking at the

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.