---
title: "Scala list高级使用"
author: "cakin24"
date: "2017-08-21T20:40:05Z"
tags: ["List", "Scala"]
categories: ["编程语言"]
slug: "scala-list"
draft: false
lastmod: "2017-08-21T20:40:05Z"
id: 2390597
url: "https://cakin24.iteye.com/blog/2390597"
---

**一 简介**

介绍List的一些高阶函数

 

**二 代码**

01. `C:\Users\lenovo>scala`
02. `Welcome to Scala2.12.1(JavaHotSpot(TM)64-BitServer VM,Java1.8.0_101).`
03. `Typein expressions for evaluation.Ortry:help.`
04. `scala> val l =List(1,2,3)`
05. `l:List[Int]=List(1,2,3)`
06. `scala> l.filter(x=>x%2==1)`
07. `res0:List[Int]=List(1,3)`
08. `scala>"99 Red Balloons".toList`
09. `res1:List[Char]=List(9,9,, R, e, d,, B, a, l, l, o, o, n, s)`
10. `scala>"99 Red Balloons".toList.filter(x=>Character.isDigit(x))`
11. `res2:List[Char]=List(9,9)`
12. `scala>"99 Red Balloons".toList.takeWhile(x=>x!='B')`
13. `res3:List[Char]=List(9,9,, R, e, d,)`