sql IN logical operation for java
by Hamid Reza Fahimi Madjd @ Apr 20, 2009
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:
true
i hope you find this tip useful;
java
recent posts
- › how to use phing to build php projects
- › slice/paging large contents using php
- › how to log methods call in php ?
- › sql IN logical operation for java
- › backup from mysql database's routines
- › how to deploy war file into web root ?
- › how to get all oracle components version ?
- › temporary/memory tables in mysql
- › Set JFreeChart data from database
- › How to search and sort primitive arrays in Java ?
archive
- › 2011/06 (1)
- › 2010/11 (1)
- › 2010/10 (1)
- › 2009/04 (2)
- › 2008/05 (1)
- › 2008/03 (1)
- › 2008/01 (4)
- › 2007/12 (4)
last tweet
- ›