Working with Java Collections and Arrays
Interop often means crossing between Clojure's immutable collections and Java's mutable ones. This lesson teaches converting, iterating, and handling primitive arrays from Clojure.
Two Collection Worlds
Clojure collections are immutable and persistent; Java collections are typically mutable. Interop requires moving values between them carefully.
Java Collections Are Seqable
Most Java collections implement Iterable, so Clojure's seq functions work on them directly.
(def jlist (java.util.ArrayList. [1 2 3]))
(println (map inc jlist))All lessons in this course
- Calling Java from Clojure
- Implementing Java Interfaces
- Leveraging Java Libraries & Tools
- Working with Java Collections and Arrays