choose

How to choose a Scala collection method to solve a problem

Note: This is an excerpt from the Scala Cookbook (partially re-worded and re-formatted for the internet). This is Recipe 10.3, How to choose a Scala collection method to solve a problem.

Back to top

Problem

There are a large number of methods available to Scala collections, and you need to choose a method to solve a problem.

Back to top

Solution

The Scala collection classes provide a wealth of methods that can be used to manipulate data. Most methods take either a function or a predicate as an argument. (A predicate is just a function that returns a Boolean.)

Table of Contents

  1. Problem
  2. Solution
Back to top

How to choose a collection class in Scala

This is an excerpt from the Scala Cookbook (partially re-worded for the internet). This is Recipe 10.2.

Scala FAQ: How do I choose a Scala collection class to solve a particular problem?

Solution

To being with, there are three main categories of collection classes to choose from: