Here you can find the source of quoteIfString(Object obj)
Parameter | Description |
---|---|
obj | the input Object (e.g. "myString") |
public static Object quoteIfString(Object obj)
//package com.java2s; public class Main { /**/*from w w w .ja va 2s. co m*/ * Turn the given Object into a String with single quotes * if it is a String; keeping the Object as-is else. * @param obj the input Object (e.g. "myString") * @return the quoted String (e.g. "'myString'"), * or the input object as-is if not a String */ public static Object quoteIfString(Object obj) { return (obj instanceof String ? quote((String) obj) : obj); } /** * Quote the given String with single quotes. * @param str the input String (e.g. "myString") * @return the quoted String (e.g. "'myString'"), * or <code>null<code> if the input was <code>null</code> */ public static String quote(String str) { return (str != null ? "'" + str + "'" : null); } }