Java String Quote quote(String s)

Here you can find the source of quote(String s)

Description

Quotes the specified string, or returns "(null)" if it is null.

License

Open Source License

Parameter

Parameter Description
s the input string, or <code>null</code>.

Return

if s != null the quoted string, otherwise the string "(null)".

Declaration

public static String quote(String s) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   www.j a  va2s.  c  o  m
     * Quotes the specified string, or returns <code>"(null)"</code> if it is
     * <code>null</code>.
     *
     * @param s
     *    the input string, or <code>null</code>.
     *
     * @return
     *    if <code>s != null</code> the quoted string, otherwise the string
     *    <code>"(null)"</code>.
     */
    public static String quote(String s) {
        if (s != null) {
            String quoted = '"' + s + '"';
            return quoted;
        } else {
            return "(null)";
        }
    }

    /**
     * Quotes the textual presentation (returned by <code>toString()</code>) of
     * the specified object, or returns <code>"(null)"</code> if the object is
     * <code>null</code>.
     *
     * @param o
     *    the object, or <code>null</code>.
     *
     * @return
     *    if <code>o != null</code> then <code>o.toString()</code> quoted,
     *    otherwise the string <code>"(null)"</code>.
     *
     * @since XINS 1.0.1
     */
    public static String quote(Object o) {
        String s = (o == null) ? null : o.toString();
        return quote(s);
    }
}

Related

  1. quote(String s)
  2. quote(String s)
  3. quote(String s)
  4. quote(String s)
  5. quote(String s)
  6. quote(String s, char ch)
  7. quote(String s, String nullResult)
  8. quote(String s, String specials, char quoteChar)
  9. quote(String str)