a vector is a collection of values indexed by contiguous integers. a vector is created by using the vector method in clojure.
example
following is an example of creating a vector in clojure.
(ns clojure.examples.example (:require [clojure.set :as set]) (:gen-class)) (defn example [] (println (vector 1 2 3))) (example)
output
the above code produces the following output.
[1 2 3]
following are the methods available in clojure.
| sr.no. | vectors & description |
|---|---|
| 1 |
vector-of
creates a new vector of a single primitive type âtâ, where âtâ is one of :int :long :float :double :byte :short :char or :boolean. |
| 2 |
nth
this function returns the item in the nth position in the vector. |
| 3 |
get
returns the element at the index position in the vector. |
| 4 |
conj
appends an element to the vector and returns the new set of vector elements. |
| 5 |
pop
for a list or queue, returns a new list/queue without the first item, for a vector, returns a new vector without the last item. |
| 6 |
subvec
returns a sub vector from a starting and ending index. |