sql IN logical operation for java
Hi,
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) {
Arrays.sort(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:truei hope you find this tip useful;
Labels: java

0 Comments:
Post a Comment
<< Home