How to get the keys from ContentValues?

android, java

Solution

According to the doc, the "valueSet()" method returns a set of all keys and values. You can then use an iterator on the resultant Set and getKey() on each of the iterated Entry elements to collect into a String array.

Problem

My ContentValues object has string keys, and I would like to get a String[] result having all the keys in it? How do I iterate a ContentValues object? EDIT 1 After getting two responses I came up with this, do you see problems with it? ``` ArrayList<String> ar = new ArrayList<String>(); ContentValues cv=data; Set<Entry<String, Object>> s=cv.valueSet(); for (Entry<String, Object> entry : s) { ar.add(entry.getKey()); } String[] projection=new String[ar.size()]; ar.toArray(projection); ```

Original source