sql IN logical operation for java

by Hamid Reza Fahimi Madjd @ Apr 20, 2009

have you ever needed sql IN for java language ?
OK, in this post I'm going to use new java 5 feature (varargs method) to simulate sql IN:

public static boolean in(int i, int... ints) {
return Arrays.binarySearch(ints, i) >= 0;

as you see, our function gets 2 parameters, first one is your desired value and second one is your search list.
now, when you call the method:

public static void main(String[] args) {
System.out.println(in(1, 2, 3, 4, 5, 1));

it returns:


i hope you find this tip useful;


add your comment

name (required)
email (required)

not readable? sorry, click here

last tweet

Developed withDeveloped with
Clicky Web Analytics