Clojure - Vectors subvec



Returns a sub vector from a starting and ending index.

Syntax

Following is the syntax.

(subvec vec start end)

Parameters − ‘vec’ is the vector set of elements. ‘start’ is the starting index. ‘end’ is the ending index.

Return Value − Returns the new vector from the starting to the ending index.

Example

Following is an example of subvec in Clojure.

(ns clojure.examples.example
   (:gen-class))
(defn example []
   (println (subvec (vector 1 2 3 4 5 6 7) 2 5)))
(example)

Output

The above code produces the following output.

[3 4 5]
clojure_vectors.htm
Advertisements