Into the Unknown
A blog about a lesser known Eclipse Collections method
What am I getting into now?
Eclipse Collections has a method named
into that was added in the 8.0 release. The signature of
into is defined as follows on the
This method can be used to transfer the contents of any
RichIterable “into” a target collection. The following examples are collections that are “unknown” as Eclipse Collections converter methods, but can be used just fine with
public void intoTheUnknown()
var integers = Interval.oneTo(10);
var into1 = integers.into(new CopyOnWriteArrayList<>());
var into2 = integers.into(new CopyOnWriteArraySet<>());
var into3 = integers.into(new ArrayDeque<>());
var into4 = integers.into(new LinkedList<>());
var into5 = integers.into(new Stack<>());
var checkedList =
Collections.checkedList(new ArrayList<>(), Integer.class);
var into6 = integers.into(checkedList);
var checkedSet =
Collections.checkedSet(new HashSet<>(), Integer.class);
var into7 = integers.into(checkedSet);
into method is also useful when you want to drain multiple source collections into the same target collection.
public void intoList()
var target = Interval.oneTo(3).into(new ArrayList<>());
That’s it. That’s the blog. I hope you enjoyed this short technical Java w/ Eclipse Collections blog.
I am a Project Lead and Committer for the Eclipse Collections OSS project at the Eclipse Foundation. Eclipse Collections is open for contributions. If you like the library, you can let us know by starring it on GitHub.