Java tutorial
//package com.java2s; /* * Copyright 2015, Yahoo Inc. * Copyrights licensed under the Apache 2.0 License. * See the accompanying LICENSE file for terms. */ import android.content.ContentValues; public class Main { /** * Put an arbitrary object into a {@link ContentValues} * * @param target the ContentValues store * @param key the key to use * @param value the value to store */ public static void putInto(ContentValues target, String key, Object value, boolean errorOnFail) { if (value == null) { target.putNull(key); } else if (value instanceof Boolean) { target.put(key, (Boolean) value); } else if (value instanceof Byte) { target.put(key, (Byte) value); } else if (value instanceof Double) { target.put(key, (Double) value); } else if (value instanceof Float) { target.put(key, (Float) value); } else if (value instanceof Integer) { target.put(key, (Integer) value); } else if (value instanceof Long) { target.put(key, (Long) value); } else if (value instanceof Short) { target.put(key, (Short) value); } else if (value instanceof String) { target.put(key, (String) value); } else if (value instanceof byte[]) { target.put(key, (byte[]) value); } else if (errorOnFail) { throw new UnsupportedOperationException("Could not handle type " + value.getClass()); } } }