Code example for Map

Methods: isEmpty, keySet

0
    /** 
     * Returns an array containing the string names in this object. This method 
     * returns null if this object contains no mappings. 
     */ 
    public JSONArray names() {
        return nameValuePairs.isEmpty()
                ? null 
                : new JSONArray(new ArrayList<String>(nameValuePairs.keySet()));
    } 
 
    /** 
     * Encodes this object as a compact JSON string, such as: 
     * <pre>{"query":"Pizza","locations":[94043,90210]}</pre> 
     */ 
    @Override public String toString() {
        try { 
            JSONStringer stringer = new JSONStringer();
            writeTo(stringer);
            return stringer.toString();
        } catch (JSONException e) {
            return null;