Into the Unknown

Photo by Mario Dobelmann on Unsplash

What am I getting into now?

The method into on RichIterable
@Test
public void intoTheUnknown()
{
var integers = Interval.oneTo(10);

var into1 = integers.into(new CopyOnWriteArrayList<>());
Assertions.assertEquals(integers, into1);

var into2 = integers.into(new CopyOnWriteArraySet<>());
Assertions.assertEquals(integers.toSet(), into2);

var into3 = integers.into(new ArrayDeque<>());
Assertions.assertEquals(integers.toBag(),
Bags.mutable.withAll(into3));

var into4 = integers.into(new LinkedList<>());
Assertions.assertEquals(integers, into4);

var into5 = integers.into(new Stack<>());
Assertions.assertEquals(integers, into5);

var checkedList =
Collections.checkedList(new ArrayList<>(), Integer.class);
var into6 = integers.into(checkedList);
Assertions.assertEquals(integers, into6);

var checkedSet =
Collections.checkedSet(new HashSet<>(), Integer.class);
var into7 = integers.into(checkedSet);
Assertions.assertEquals(integers.toSet(), into7);
}
@Test
public void intoList()
{
var target = Interval.oneTo(3).into(new ArrayList<>());
Interval.fromTo(4,6).into(target);
Interval.fromTo(7,10).into(target);
Assertions.assertEquals(Interval.oneTo(10), target);
}

--

--

--

Java Champion. Creator of the Eclipse Collections OSS Java library (http://www.eclipse.org/collections/). Inspired by Smalltalk. Opinions are my own.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Beyond Unit Tests

SGB(SubGame) to be Listed on LBank

Disk Editor For Mac

These are the 5 worst things any developer could do

How to build Enterprise Level Web Applications using Java?

DREAM 11 is fantasy app ..But how did AWS helped to fullfill their dreams of DREAM11…..

Problem solving using Swift: Part 2

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Donald Raab

Donald Raab

Java Champion. Creator of the Eclipse Collections OSS Java library (http://www.eclipse.org/collections/). Inspired by Smalltalk. Opinions are my own.

More from Medium

Sample code for IBM Event Streams Coding Challenge

Morris Traversal for Binary Trees

From Zero to Hero: Java Part 1 — Basics

How to implement Matrix Multiplication using Map-Reduce?