Question: In my project I have to select multiple values and pass it to a query. i.e page1 contains checkboxes. I am storing the selected checkbox id's into an array.
I am shuffling that array and getting the values randomly. Now I need to pass these random values to a query. Using IN operator in database I can pass the values 
statically but how can I pass the values dynamcially to the query. 

For ex:(Passing values statically)

```
SELECT * FROM Persons WHERE person_id IN ('21','22')

```

In the above query the id's 21 and 22 are know previously and so we are passing statically but I want to send the values to query dynamically.

```
Page1:
public static ArrayList<String> chksublist = new ArrayList<String>();

Page2:
 Collections.shuffle(chksublist );
SELECT * FROM Persons WHERE person_id IN ('21','22')
In the above line I want to send the random values which are in chksublist array.

```

Answer: 
`String query = "SELECT * FROM Persons WHERE person_id IN (" + TextUtils.join(",", chksublist) + ")";`

But shuffling the `chksublist` before sending it to your SQL query has no impact on the result set you get from SQL. It will not randomly permute your results. Remove `Collections.shuffle(chksublist);` and use

`String query = "SELECT * FROM Persons WHERE person_id IN (" + TextUtils.join(",", chksublist) + ") ORDER BY RANDOM()";`
see how values are dynamicaly passed

```
  // Getting single contact
 public Contact getContact(int id) {
SQLiteDatabase db = this.getReadableDatabase();

Cursor cursor = db.query(TABLE_CONTACTS, new String[] { KEY_ID,
        KEY_NAME, KEY_PH_NO }, KEY_ID + "=?",
        new String[] { String.valueOf(id) }, null, null, null, null);

 // here   new String[] { String.valueOf(id) } value is added dynamicaly which is passed to the function
if (cursor != null)
    cursor.moveToFirst();

Contact contact = new Contact(Integer.parseInt(cursor.getString(0)),
        cursor.getString(1), cursor.getString(2));
// return contact
return contact;
 }

```