Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7494395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:31:31+00:00 2026-05-29T17:31:31+00:00

I am creating a Clojure interface to a Java API with a method that

  • 0

I am creating a Clojure interface to a Java API with a method that returns a java.util.LinkedHashSet.

Firstly, is the idiomatic Clojure way of handling this to convert the LinkedHashSet to a clojure data structure?

Secondly, what is the best method for converting Java collections into Clojure data structures?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T17:31:33+00:00Added an answer on May 29, 2026 at 5:31 pm

    There are lots of options, since Clojure plays very nicely with Java collections. It depends on exactly what data structure you want to use in Clojure.

    Here’s some examples:

    ;; create a HashSet
    (def a (java.util.HashSet.))
    (dotimes [i 10] (.add a i))
    
    ;; Get all the values as a sequence 
    (seq a)
    => (0 1 2 3 4 5 6 7 8 9)
    
    ;; build a new HashSet containing the values from a 
    (into #{} a)
    #{0 1 2 3 4 5 6 7 8 9}
    
    ;; Just use the HashSet directly (high performance, no copy required)
    (.contains a 1)
    => true
    (.contains a 100)
    => false
    

    Regarding when to use each of these, I’d suggest the following advice:

    • If you are trying to wrap a Java library and present a clean Clojure API, then I’d suggest converting to the equivalent Clojure data structures. This is what Clojure users will expect, and you can hide the potentially messy Java interop details. As a bonus, this will make things immutable so that you don’t run the risk of Java collections mutating while you use them.
    • If you just want to use the Java API quickly and efficiently, just use Java interop directly on the Java collections.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a library that includes both Clojure and Java code, and would like
It seems that Clojure 1.2.0 has a definterface form, apparently for creating Java interfaces,
I got an unexpected closure when creating a nested class. I suspect that this
Clojure is awesome, we all know this, but that's not the point. I'm wondering
Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
(creating a separate question after comments on this: Javascript redeclared global variable overrides old
Should I feel wary about creating clojure keywords which have non-existent namespaces? An example
I'm creating a convenience macro. Part of the convenience is that a regular expression
I have a java.util.HashMap object m (a return value from a call to Java

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.