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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:15:20+00:00 2026-05-26T16:15:20+00:00

For the one millionth time, I would have liked to use an IN operator

  • 0

For the one millionth time, I would have liked to use an IN operator in Java, similar to the IN operator in SQL. It could just be implemented as compiler syntactic sugar. So this

if (value in (a, b, c)) {
}
else if (value in (d, e)) {
}

…would really be awesome. In fact, the above is the same as the rather verbose (and not adapted for primitives) construct here:

if (Arrays.asList(a, b, c).contains(value)) {
}
else if (Arrays.asList(d, e).contains(value)) {
}

Or like this for int, long and similar types:

switch (value) {
  case a:
  case b:
  case c:
    // ..
    break;

  case d:
  case e:
    // ..
    break;
 }

Or maybe there could be even more efficient implementations.

Question:

Is something like this going to be part of Java 8? How can I make such a suggestion, if not? Or is there any equivalent construct that I could use right now?

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

    Using op4j:

    Op.onListFor(a,b,c).get().contains(value);
    

    Using the same approach, you could create a helper classes Is with a method in:

    class Is<T> {
        private T value;
    
        public Is( T value ) { this.value = value; }
    
        public boolean in( T... set ) {
            for( T item : set ) {
                if( value.equals( item ) ) {
                    return true;
                }
            }
    
            return false;
        }
    
        public static <T> Is<T> is( T value ) {
            return new Is<T>( value );
        }
    }
    

    with a static import, you can write:

    if(is(value).in(a,b,c)) {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one million URL list to fetch. I use this list as nutch
I have about 50 million lists of strings in Python like this one: [1,
I have two arrays, one is very large (more than million entries) and other
Say you have a MySQL 5.0 MyISAM table with 100 million rows, with one
One can say a type parameter T must have a specific supertype S_1: class
I have a Youtube like web-page where users upload&watch videos. I would like to
I have a table to entities (lets call them people) and properties (one person
I've created a couple of little few page long websites for one time projects
I have a huge table with more than one hundred million of rows and
I am using SQL Server 2008 R2 and I have a conversion written in

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.