Java tutorial
//package com.java2s; import android.text.TextUtils; public class Main { public static String convertToQuotedString(String string) { if (TextUtils.isEmpty(string)) return ""; final int lastPos = string.length() - 1; if (lastPos < 0 || (string.charAt(0) == '"' && string.charAt(lastPos) == '"')) { return string; } return "\"" + string + "\""; } }