# ScalaArrayNote

valnumbers =Array(1,2,3,4)//声明一个数组对象valfirst = numbers(0)// 读取第一个元素numbers(3) =100// 替换第四个元素为100valbiggerNumbers = numbers.map(_ *2)// 所有元素乘2

Scala提供了大量的集合操作：

def ++[B](that: GenTraversableOnce[B]):Array[B]

vala =Array(1,2)valb =Array(3,4)valc = a ++ b//c中的内容是(1,2,3,4)

def ++:[B >: A, That](that: collection.Traversable[B])(implicit bf: CanBuildFrom[Array[T], B, That]): That

val a = List(1,2)    val b =scala.collection.mutable.LinkedList(3,4)    val c = a ++: b    println(c.getClass().getName())// c的类型是：scala.collection.mutable.LinkedList

def +:(elem: A):Array[A]

vala = List(1,2)valc =0+: a// c中的内容是 （0,1,2）

def :+(elem: A):Array[A]

def /:[B](z: B)(op: (B, T) �6�0 B): B

vala = List(1,2,3,4)valc = (10/: a)(_+_)// 1+2+3+4+10vald = (10/: a)(_*_)// 1*2*3*4*10println("c:"+c)// c:20println("d:"+d)// d:240

def :\[B](z: B)(op: (T, B) �6�0 B): B

foldRight的简写

vala = List(1,2,3,4)valb =newStringBuilder()valc = a.addString(b)// c中的内容是  1234

def addString(b: StringBuilder, sep: String): StringBuilder

vala = List(1,2,3,4)valb =newStringBuilder()valc = a.addString(b,",")    println("c:  "+c)// c:  1,2,3,4

def addString(b: StringBuilder, start: String, sep: String, end: String): StringBuilder

vala = List(1,2,3,4)valb =newStringBuilder()valc = a.addString(b,"{",",","}")    println("c:  "+c)// c:  {1,2,3,4}

def aggregate[B](z: �6�0 B)(seqop: (B, T) �6�0 B, combop: (B, B) �6�0 B): B

defmain(args:Array[String]) {vala = List(1,2,3,4)valc = a.par.aggregate(5)(seqno,combine)    println("c:"+c)  }defseqno(m:Int,n:Int): Int ={vals ="seq_exp=%d+%d"println(s.format(m,n))returnm+n  }defcombine(m:Int,n:Int): Int ={vals ="com_exp=%d+%d"println(s.format(m,n))returnm+n  }/**

seq_exp=5+3

seq_exp=5+2

seq_exp=5+4

seq_exp=5+1

com_exp=6+7

com_exp=8+9

com_exp=13+17

c:30

*/

val c = a.par.aggregate(5)(_+_,_+_)

def apply(i: Int): T

valfirst = numbers(0)// 读取第一个元素

def canEqual(that: Any): Boolean

def charAt(index: Int): Char

valchars=Array('a','b','c')println("c:"+chars.charAt(0))//结果 a

def clone():Array[T]

valchars=Array('a','b','c')    println(a.apply(2))    val newchars =chars.clone()

def collect[B](pf: PartialFunction[A, B]):Array[B]

valchars =Array('a','b','c')valnewchars = chars.collect(fun)  println("newchars:"+newchars.mkString(","))//我们通过下面的偏函数，把chars数组的小写a转换为大写的Avalfun:PartialFunction[Char,Char] = {case'a'=>'A'casex => x  }/**输出结果是 newchars:A,b,c */

def collectFirst[B](pf: PartialFunction[T, B]): Option[B]

valarr =Array(1,'a',"b")//定义一个偏函数，要求当被执行对象为Int类型时，进行乘100的操作，对于上面定义的对象arr来说，只有第一个元素符合要求valfun:PartialFunction[Any,Int] = {    case x:Int => x*100}//计算valvalue = arr.collectFirst(fun)  println("value:"+value)//另一种写法valvalue = arr.collectFirst({case x:Int => x*100})

def combinations(n: Int): collection.Iterator[Array[T]]

valarr =Array("a","b","c")valnewarr = arr.combinations(2)    newarr.foreach((item) => println(item.mkString(",")))/**

a,b

a,c

b,c

*/

def contains[A1 >: A](elem: A1): Boolean

def containsSlice[B](that: GenSeq[B]): Boolean

vala = List(1,2,3,4)valb = List(2,3)    println(a.containsSlice(b))//true

def copyToArray(xs:Array[A]): Unit

copyToArray(xs:Array[A], start: Int): Unit

vala =Array('a','b','c')valb :Array[Char] =newArray(5)a.copyToArray(b)/**b中元素 ['a','b','c',0,0]*/a.copyToArray(b,1)/**b中元素 [0,'a',0,0,0]*/a.copyToArray(b,1,2)/**b中元素 [0,'a','b',0,0]*/

def copyToBuffer[B >: A](dest: Buffer[B]): Unit

val a =Array('a','b','c')    val b:ArrayBuffer[Char]  =ArrayBuffer()    a.copyToBuffer(b)    println(b.mkString(","))

def corresponds[B](that: GenSeq[B])(p: (T, B) �6�0 Boolean): Boolean

val a =Array(1,2,3)val b =Array(4,5,6)println(a.corresponds(b)(_<_))//true

def count(p: (T) �6�0 Boolean): Int

val a =Array(1,2,3)    println(a.count({x:Int => x >2}))// count = 1

def diff(that: collection.Seq[T]):Array[T]

vala =Array(1,2,3,4)valb =Array(4,5,6,7)valc = a.diff(b)println(c.mkString)//1,2,3

def distinct:Array[T]

vala =Array(1,2,3,4,4,5,6,6)valc = a.distinctprintln(c.mkString(","))// 1,2,3,4,5,6

def drop(n: Int):Array[T]

vala =Array(1,2,3,4)valc = a.drop(2)println(c.mkString(","))// 3,4

def dropRight(n: Int):Array[T]

def dropWhile(p: (T) �6�0 Boolean):Array[T]

//下面去除大于2的，第一个元素 3 满足，它后面的元素 2 不满足，所以返回 2,3,4vala =Array(3,2,3,4)valc = a.dropWhile( {x:Int => x >2} )println(c.mkString(","))//如果数组 a 是下面这样，第一个元素就不满足，所以返回整个数组 1, 2, 3,4vala =Array(1,2,3,4)

def endsWith[B](that: GenSeq[B]): Boolean

val a =Array(3,2,3,4)val b =Array(3,4)println(a.endsWith(b))//true

def exists(p: (T) �6�0 Boolean): Boolean

val a =Array(3,2,3,4) println(a.exists( {x:Int => x==3} ))//trueprintln(a.exists( {x:Int => x==30} ))//false

def filter(p: (T) �6�0 Boolean):Array[T]

vala=Array(3,2,3,4)val b =a.filter( {x:Int => x>2} )println(b.mkString(","))//3,3,4

def filterNot(p: (T) �6�0 Boolean):Array[T]

def find(p: (T) �6�0 Boolean): Option[T]

vala =Array(1,2,3,4)valb = a.find( {x:Int => x>2} )println(b)// Some(3)

def flatMap[B](f: (A) �6�0 GenTraversableOnce[B]):Array[B]

vala =Array(1,2,3,4)valb = a.flatMap(x=>1to x)println(b.mkString(","))/**

1,1,2,1,2,3,1,2,3,4

1

1,2

1,2,3

1,2,3,4

*/

def flatten[U](implicit asTrav: (T) �6�0 collection.Traversable[U], m: ClassTag[U]):Array[U]

val dArr =Array(Array(1,2,3),Array(4,5,6))val c = dArr.flattenprintln(c.mkString(","))//1,2,3,4,5,6

-def fold[A1 >: A](z: A1)(op: (A1, A1) �6�0 A1): A1

defseqno(m:Int,n:Int): Int ={vals ="seq_exp=%d+%d"println(s.format(m,n))returnm+n  }defcombine(m:Int,n:Int): Int ={vals ="com_exp=%d+%d"println(s.format(m,n))returnm+n  }vala =Array(1,2,3,4)valb = a.fold(5)(seqno)/** 运算过程

seq_exp=5+1

seq_exp=6+2

seq_exp=8+3

seq_exp=11+4

*/valc = a.par.aggregate(5)(seqno,combine)/** 运算过程

seq_exp=5+1

seq_exp=5+4

seq_exp=5+3

com_exp=8+9

seq_exp=5+2

com_exp=6+7

com_exp=13+17

*/

-def foldLeft[B](z: B)(op: (B, T) �6�0 B): B

defseqno(m:Int,n:Int): Int ={vals ="seq_exp=%d+%d"println(s.format(m,n))returnm+n  }vala =Array(1,2,3,4)valb = a.foldLeft(5)(seqno)/** 运算过程

seq_exp=5+1

seq_exp=6+2

seq_exp=8+3

seq_exp=11+4

*//**

*/

-def foldRight[B](z: B)(op: (B, T) �6�0 B): B

defseqno(m:Int,n:Int): Int ={vals ="seq_exp=%d+%d"println(s.format(m,n))returnm+n  }vala =Array(1,2,3,4)valb = a.foldRight(5)(seqno)/** 运算过程

seq_exp=4+5

seq_exp=3+9

seq_exp=2+12

seq_exp=1+14

*//**

*/

-def forall(p: (T) �6�0 Boolean): Boolean

vala =Array(1,2,3,4)valb = a.forall( {x:Int => x>0})//truevalb = a.forall( {x:Int => x>2})//false

-def foreach(f: (A) �6�0 Unit): Unit

vala =Array(1,2,3,4)valb = a.forall( {x:Int => x>0})//truevalb = a.forall( {x:Int => x>2})//false

-def foreach(f: (A) �6�0 Unit): Unit

vala =Array(1,2,3,4)    a.foreach(x => println(x*10))/**

10

20

30

40

*/

-def groupBy[K](f: (T) �6�0 K): Map[K,Array[T]]

val a =Array(1,2,3,4)    val b = a.groupBy( x=>x match {casexif(x <3)=>"small"case_=>"big"})

-def grouped(size: Int): collection.Iterator[Array[T]]

vala =Array(1,2,3,4,5)valb = a.grouped(3).toListb.foreach((x) => println("第"+(b.indexOf(x)+1)+"组:"+x.mkString(",")))/**

*/

-def hasDefiniteSize: Boolean

vala=Array(1,2,3,4,5)println(a.hasDefiniteSize)//true

-def indexOf(elem: T): Int

vala=Array(1,3,2,3,4)println(a.indexOf(3))// return 1

-def indexOf(elem: T, from: Int): Int

vala=Array(1,3,2,3,4)println(a.indexOf(3,2))// return 3

-def indexOfSlice[B >: A](that: GenSeq[B]): Int

val a =Array(1,3,2,3,4)    val b =Array(2,3)    println(a.indexOfSlice(b))// return 2

-def indexOfSlice[B >: A](that: GenSeq[B], from: Int): Int

val a =Array(1,3,2,3,2,3,4)    val b =Array(2,3)    println(a.indexOfSlice(b,3))// return 4

-def indexWhere(p: (T) �6�0 Boolean): Int

val a =Array(1,2,3,4)    println(a.indexWhere( {x:Int => x>3}))// return 3

-def indexWhere(p: (T) �6�0 Boolean, from: Int): Int

val a =Array(1,2,3,4,5,6)    println(a.indexWhere( {x:Int => x>3},4))// return 4

-def indices: collection.immutable.Range

vala =Array(10,2,3,40,5)valb = a.indices    println(b.mkString(","))// 0,1,2,3,4

-def init:Array[T]

vala =Array(10,2,3,40,5)valb = a.init    println(b.mkString(","))// 10, 2, 3, 40

-def inits: collection.Iterator[Array[T]]

vala =Array(1,2,3,4,5)valb = a.inits.toListfor(i <-1to b.length){vals ="第%d个值：%s"println(s.format(i,b(i-1).mkString(",")))    }/**计算结果

*/

-def intersect(that: collection.Seq[T]):Array[T]

vala =Array(1,2,3,4,5)valb =Array(3,4,6)valc = a.intersect(b)    println(c.mkString(","))//return 3,4

-def isDefinedAt(idx: Int): Boolean

vala=Array(1,2,3,4,5)    println(a.isDefinedAt(1))// trueprintln(a.isDefinedAt(10))// false

-def isEmpty: Boolean

-def isTraversableAgain: Boolean

-def iterator: collection.Iterator[T]

vala =Array(1,2,3,4,5)valb = a.iterator//此时就可以通过迭代器访问 b

-def last: T

vala=Array(1,2,3,4,5)    println(a.last)// return  5

-def lastIndexOf(elem: T): Int

vala=Array(1,4,2,3,4,5)    println(a.lastIndexOf(4))// return  4

-def lastIndexOf(elem: T, end: Int): Int

vala=Array(1,4,2,3,4,5)    println(a.lastIndexOf(4,3))// return  1

-def lastIndexOfSlice[B >: A](that: GenSeq[B]): Int

val a =Array(1,4,2,3,4,5,1,4)    val b =Array(1,4)    println(a.lastIndexOfSlice(b))// return  6

-def lastIndexOfSlice[B >: A](that: GenSeq[B], end: Int): Int

val a =Array(1,4,2,3,4,5,1,4)    val b =Array(1,4)    println(a.lastIndexOfSlice(b,4))// return  0

-def lastIndexWhere(p: (T) �6�0 Boolean): Int

val a =Array(1,4,2,3,4,5,1,4)    val b =Array(1,4)    println(a.lastIndexWhere( {x:Int => x<2}))// return  6

-def lastIndexWhere(p: (T) �6�0 Boolean, end: Int): Int

val a =Array(1,4,2,3,4,5,1,4)    val b =Array(1,4)    println(a.lastIndexWhere( {x:Int => x<2},2))// return  0

-def lastOption: Option[T]

vala=Array(1,2,3,4,5)    println(a.lastOption)// return  Some(5)

-deflength: Int

vala=Array(1,2,3,4,5)    println(a.length)// return  5

-def lengthCompare(len: Int): Int

x <0ifthis.lengthlength==lenx >0ifthis.length>len

-def map[B](f: (A) �6�0 B):Array[B]

vala =Array(1,2,3,4,5)valb = a.map( {x:Int => x*10})    println(b.mkString(","))// 10,20,30,40,50

-def max: A

vala=Array(1,2,3,4,5)    println(a.max)// return  5

-def maxBy[B](f: (A) �6�0 B): A

val a =Array(1,2,3,4,5)    println(a.maxBy( {x:Int => x >2}))// return  3

-def mkString: String

vala=Array(1,2,3,4,5)    println(a.mkString)// return  12345

-def mkString(sep: String): String

vala=Array(1,2,3,4,5)    println(a.mkString(","))// return  1,2,3,4,5

-def mkString(start: String, sep: String, end: String): String

vala=Array(1,2,3,4,5)    println(a.mkString("{",",","}"))// return  {1,2,3,4,5}

-def nonEmpty: Boolean

vala =Array(1,2,3,4,5)valb = a.padTo(7,9)//需要一个长度为 7  的新序列，空出的填充 9println(b.mkString(","))// return  1,2,3,4,5,9,9

-def par: ParArray[T]

vala =Array(1,2,3,4,5)valb = a.par//  "ParArray" size = 5

-def partition(p: (T) �6�0 Boolean): (Array[T],Array[T])

val a =Array(1,2,3,4,5)    val b:(Array[Int],Array[Int]) = a.partition( {x:Int => x %2==0})    println(b._1.mkString(","))// return  2,4println(b._2.mkString(","))// return  1,3,5

-def patch(from: Int, that: GenSeq[A], replaced: Int):Array[A]

vala =Array(1,2,3,4,5)valb =Array(3,4,6)valc = a.patch(1,b,2)    println(c.mkString(","))// return 1,3,4,6,4,5/**从 a 的第二个元素开始，取两个元素，即 2和3 ，这两个元素被替换为 b的内容*/

-def permutations: collection.Iterator[Array[T]]

vala =Array(1,2,3,4,5)valb = a.permutations.toList// b 中将有120个结果，知道排列组合公式的，应该不难理解吧/**如果是combinations*/valb = a.combinations(5).toList// b 中只有一个，因为不管怎样排列，都是这5个数字组成，所以只能保留第一个

-def prefixLength(p: (T) �6�0 Boolean): Int

vala =Array(1,2,3,4,1,2,3,4)valb = a.prefixLength( {x:Int => x<3})// b = 2

-def product: A

val a =Array(1,2,3,4,5)    val b = a.product      // b =120（1*2*3*4*5）

-def reduce[A1 >: A](op: (A1, A1) �6�0 A1): A1

valfun:PartialFunction[Any,Int] = {case'a'=>'A'casex:Int => x*100}vala =Array(1,2,3,4,5)valb = a.reduce(seqno)  println(b)// 15/**

seq_exp=1+2

seq_exp=3+3

seq_exp=6+4

seq_exp=10+5

*/

-def reduceLeft[B >: A](op: (B, T) �6�0 B): B

-def reduceRight[B >: A](op: (T, B) �6�0 B): B

-def reduceLeftOption[B >: A](op: (B, T) �6�0 B): Option[B]

-def reduceRightOption[B >: A](op: (T, B) �6�0 B): Option[B]

-def reverse:Array[T]

vala =Array(1,2,3,4,5)valb = a.reverse    println(b.mkString(","))//5,4,3,2,1

-def reverseIterator: collection.Iterator[T]

-def reverseMap[B](f: (A) �6�0 B):Array[B]

vala =Array(1,2,3,4,5)valb = a.reverseMap( {x:Int => x*10} )    println(b.mkString(","))// 50,40,30,20,10

-def sameElements(that: GenIterable[A]): Boolean

val a =Array(1,2,3,4,5)    val b =Array(1,2,3,4,5)    println(a.sameElements(b))// trueval c =Array(1,2,3,5,4)    println(a.sameElements(c))// false

-def scan[B >: A, That](z: B)(op: (B, B) �6�0 B)(implicit cbf: CanBuildFrom[Array[T], B, That]): That

vala =Array(1,2,3,4,5)valb = a.scan(5)(seqno)    println(b.mkString(","))// 5,6,8,11,15,20

-def scanLeft[B, That](z: B)(op: (B, T) �6�0 B)(implicit bf: CanBuildFrom[Array[T], B, That]): That

-def scanRight[B, That](z: B)(op: (T, B) �6�0 B)(implicit bf: CanBuildFrom[Array[T], B, That]): That

-def segmentLength(p: (T) �6�0 Boolean, from: Int): Int

vala =Array(1,2,3,1,1,1,1,1,4,5)valb = a.segmentLength( {x:Int => x <3},3)// 5

-def seq: collection.mutable.IndexedSeq[T]

-def size: Int

-def slice(from: Int, until: Int):Array[T]

vala =Array(1,2,3,4,5)valb = a.slice(1,3)    println(b.mkString(","))// 2,3

-def sliding(size: Int): collection.Iterator[Array[T]]

vala =Array(1,2,3,4,5)valb = a.sliding(3).toListfor(i<-0to b.length-1){vals ="第%d个：%s"println(s.format(i,b(i).mkString(",")))    }/**

*/

-def sliding(size: Int, step: Int): collection.Iterator[Array[T]]

vala =Array(1,2,3,4,5)valb = a.sliding(3,2).toList//第一个从1开始， 第二个从3开始，因为步进是 2for(i<-0to b.length-1){vals ="第%d个：%s"println(s.format(i,b(i).mkString(",")))    }/**

*/

-def sortBy[B](f: (T) �6�0 B)(implicit ord: math.Ordering[B]):Array[T]

vala =Array(3,2,1,4,5)valb = a.sortBy( {x:Int => x})    println(b.mkString(","))// 1,2,3,4,5

-def sortWith(lt: (T, T) �6�0 Boolean):Array[T]

vala =Array(3,2,1,4,5)valb = a.sortWith(_.compareTo(_) >0)// 大数在前println(b.mkString(","))// 5,4,3,2,1

-def sorted[B >: A](implicit ord: math.Ordering[B]):Array[T]

vala =Array(3,2,1,4,5)valb = a.sorted        println(b.mkString(","))// 1,2,3,4,5

-def span(p: (T) �6�0 Boolean): (Array[T],Array[T])

vala =Array(3,2,1,4,5)valb = a.span( {x:Int => x >2})    println(b._1.mkString(","))//  3println(b._2.mkString(","))//  2,1,4,5

-def splitAt(n: Int): (Array[T],Array[T])

vala =Array(3,2,1,4,5)valb = a.splitAt(2)    println(b._1.mkString(","))//  3,2println(b._2.mkString(","))//  1,4,5

-def startsWith[B](that: GenSeq[B], offset: Int): Boolean

val a =Array(0,1,2,3,4,5)    val b =Array(1,2)    println(a.startsWith(b,1))//  true

-def startsWith[B](that: GenSeq[B]): Boolean

val a =Array(1,2,3,4,5)    val b =Array(1,2)    println(a.startsWith(b))//  true

-def stringPrefix: String

vala=Array(0,1,2,3,4,5)    println(a.toString())//[I@3daa57fbval b =a.stringPrefix    println(b)//[I

-def subSequence(start: Int, end: Int): CharSequence

valchars =Array('a','b','c','d')valb = chars.subSequence(1,3)    println(b.toString)//  bc

-def sum: A

vala=Array(1,2,3,4,5)    val b =a.sum//  15

-def tail:Array[T]

vala =Array(1,2,3,4,5)valb = a.tail//  2,3,4,5

-def take(n: Int):Array[T]

vala =Array(1,2,3,4,5)valb = a.take(3)//  1,2,3

-def takeRight(n: Int):Array[T]

vala =Array(1,2,3,4,5)valb = a.takeRight(3)//  3,4,5

-def takeWhile(p: (T) �6�0 Boolean):Array[T]

vala =Array(1,2,3,4,5)valb = a.takeWhile( {x:Int => x <3})//  1,2

-def toArray:Array[A]

-def toBuffer[A1 >: A]: Buffer[A1]

-def toIndexedSeq: collection.immutable.IndexedSeq[T]

-def toIterable: collection.Iterable[T]

-def toIterator: collection.Iterator[T]

-def toList: List[T]

-def toMap[T, U]: Map[T, U]

valchars =Array(("a","b"),("c","d"),("e","f"))valb = chars.toMap    println(b)//Map(a -> b, c -> d, e -> f)

-def toSeq: collection.Seq[T]

-def toSet[B >: A]: Set[B]

-def toStream: collection.immutable.Stream[T]

-def toVector: Vector[T]

-def transpose[U](implicit asArray: (T) �6�0Array[U]):Array[Array[U]]

val chars =Array(Array("a","b"),Array("c","d"),Array("e","f"))    val b = chars.transpose    println(b.mkString(","))

-def union(that: collection.Seq[T]):Array[T]

vala =Array(1,2,3,4,5)valb =Array(6,7)valc = a.union(b)    println(c.mkString(","))// 1,2,3,4,5,6,7

-def unzip[T1, T2](implicit asPair: (T) �6�0 (T1, T2), ct1: ClassTag[T1], ct2: ClassTag[T2]): (Array[T1],Array[T2])

valchars =Array(("a","b"),("c","d"))valb = chars.unzip    println(b._1.mkString(","))//a,cprintln(b._2.mkString(","))//b,d

-def unzip3[T1, T2, T3](implicit asTriple: (T) �6�0 (T1, T2, T3), ct1: ClassTag[T1], ct2: ClassTag[T2], ct3: ClassTag[T3]): (Array[T1],Array[T2],Array[T3])

val chars =Array(("a","b","x"),("c","d","y"),("e","f","z"))    val b = chars.unzip3println(b._1.mkString(","))//a,c,eprintln(b._2.mkString(","))//b,d,fprintln(b._3.mkString(","))//x,y,z

-def update(i: Int, x: T): Unit

vala=Array(1,2,3,4,5)a.update(1,9)    println(a.mkString(","))//1,9,3,4,5

-def updated(index: Int, elem: A):Array[A]

vala =Array(1,2,3,4,5)valb = a.updated(1,9)    println(b.mkString(","))//1,9,3,4,5

-def view(from: Int, until: Int): IndexedSeqView[T,Array[T]]

vala =Array(1,2,3,4,5)valb = a.view(1,3)    println(b.mkString(","))//2,3

-def withFilter(p: (T) �6�0 Boolean): FilterMonadic[T,Array[T]]

val a =Array(1,2,3,4,5)    val b = a.withFilter( {x:Int => x>3}).map(x=>x)    println(b.mkString(","))//4,5

-def zip[B](that: GenIterable[B]):Array[(A, B)]

vala =Array(1,2,3,4,5)valb =Array(5,4,3,2,1)valc = a.zip(b)    println(c.mkString(","))//(1,5),(2,4),(3,3),(4,2),(5,1)

-def zipAll[B](that: collection.Iterable[B], thisElem: A, thatElem: B):Array[(A, B)]

vala =Array(1,2,3,4,5,6,7)valb =Array(5,4,3,2,1)valc = a.zipAll(b,9,8)//(1,5),(2,4),(3,3),(4,2),(5,1),(6,8),(7,8)vala =Array(1,2,3,4)valb =Array(5,4,3,2,1)valc = a.zipAll(b,9,8)//(1,5),(2,4),(3,3),(4,2),(9,1)

-def zipWithIndex:Array[(A, Int)]

vala =Array(10,20,30,40)valb = a.zipWithIndex    println(b.mkString(","))//(10,0),(20,1),(30,2),(40,3)