• (join coll)
  • (join separator coll)
Returns a string of all elements in coll, as returned by (seq coll),
separated by an optional separator.

2 Examples top

  • user=> (clojure.string/join ", " [1 2 3])
    "1, 2, 3"
    
  • ;; Splits a string on space character and joins 
    ;; the resulting collection with a line feed character
    
    (use '[clojure.string :only (join split)])
    
    user=> (println
             (join "\n"
               (split "The Quick Brown Fox" #"\s")))
    The
    Quick
    Brown
    Fox
    nil
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/string.clj:130 top

(defn ^String join
  "Returns a string of all elements in coll, as returned by (seq coll),
   separated by an optional separator."
  {:added "1.2"}
  ([coll]
     (apply str coll))
  ([separator coll]
     (loop [sb (StringBuilder. (str (first coll)))
            more (next coll)
            sep (str separator)]
       (if more
         (recur (-> sb (.append sep) (.append (str (first more))))
                (next more)
                sep)
         (str sb)))))
Vars in clojure.string/join:
Used in 0 other vars

Comments top

No comments for join. Log in to add a comment.